hygor Posted August 19, 2004 Posted August 19, 2004 I am trying to modify an old VB6 multiple choice quiz which read from a .dat file, into VB.net format, and convert it to read not from a .dat file but a table in a database. I have managed to change almost all I have needed to, except for the actual input strings: Private Sub newGame() Dim numWords As Integer Dim Chooseword As Integer Dim VarI As Single NumWrong.Text = "0" Template = "" TheWord.Text = "" CN = New ADODB.Connection() CN.Provider = "MICROSOFT.JET.OLEDB.4.0" 'ACCESS CONNECTION CN.Open("lessons.MDB") rs = New ADODB.Recordset() rs.Open("select HangWord from Hangman", CN, 1, 2) Do While Not rs.EOF() numWords = numWords + 1 Input(Word) Loop Close() Chooseword = Int(numWords * Rnd()) + 1 'Open App.Path & "\gamedata.dat" For Input As #1 For VarI = 1 To Chooseword 'Input #1, Word Next 'Close #1 For VarI = 1 To Len(Word) Template = Template & "_" Next VarI TheWord = Template PressedBox.Text = "" txtGuess.Visible = True MsgBox(Word) End Sub As you can see some of the old code is still in this section, for instance the Open string, however i have commented these out while i build the program. however the original coding used "for input As #1" and then has references to the #1 all of the time. I have initialised my database and am now unsure with how to have a similar method to this #1 one using .net If anyone could possibly give me any pointers/help with this I would be so grateful... I have been going in circles all day! Thanks in advance Hygor Quote
Administrators PlausiblyDamp Posted August 19, 2004 Administrators Posted August 19, 2004 Rather than using ADODB (which is the old COM way of doing things) you probably should consider ADO.Net (System.Data and related classes). Also you may want to give the database table an Identity (autonumber field) - this way every row will be assigned a unique value. You could obtain a count of words by doing a SELECT COUNT(*) from HangMan rather than looping through each record one by one.... Then instead of re-reading each record in a loop (for VarI = 1 to ChooseWord) just do a SELECT HangWord from HangMan where ID = Chooseword query. If you have more specific question when you start to implement this feel free to post again. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
hygor Posted August 19, 2004 Author Posted August 19, 2004 Cheers for the extremely quick reply... and from a fellow manc too! I am using the ADODB way as i am making a program for distribution on a CD where using SQL Server 2000 is not an option... so i just need to jump in and out of a file to get the data. Cheers, thanks to your advice I think I have made some progress, I just need to bind the data I am getting from the querys to the corrrect places, which hopefully shouldnt be too hard! Many thanks again! Quote
Administrators PlausiblyDamp Posted August 19, 2004 Administrators Posted August 19, 2004 You can still use ADO.Net to access non SQL databases, if you are using access then you will use classes under System.Data.OleDB - no need to use the ADODB as that involves all the COM interop and making sure all the ADO stuff is properly installed and registered. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
hygor Posted August 19, 2004 Author Posted August 19, 2004 Cheers for all your help mate... it seems to be running nicely now! I really appreciate it! I will stick around on these forums and hopefully I will be able to pass along something i've learned to someone who is in need of that info! Cheers again! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.