save and open button in vb6 for rpg

im trying to create a save and open function for an rpg in vb6.

Page 1 of 1

2 Replies - 4144 Views - Last Post: 05 March 2010 - 05:00 PM Rate Topic: -----

#1 mapmd1234  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 147
  • Joined: 04-December 09

save and open button in vb6 for rpg

Posted 05 March 2010 - 04:03 PM

OK, please and thank you to everyone that tries to help me. I would make this myself, but i cant comprehend the coding that everyone has posted that tells me how to do this. i have copied this example from a prior post on the subject, but i cant understand what exactly it is that i need to modify for my personal use...

'(general declaration)

Dim nFileNum As Integer, sText As String, sNextLine As String, lLineCount As Long

'==================================

Private Sub Command1_Click()

' Get a free file number
nFileNum = FreeFile

' Open a text file for input. inputbox returns the path to read the file
Open "C:\3.txt" For Input As nFileNum
lLineCount = 1
' Read the contents of the file
Do While Not EOF(nFileNum)
   Line Input #nFileNum, sNextLine
   'do something with it
   'add line numbers to it, in this case!
   sNextLine = sNextLine & vbCrLf
   sText = sText & lLineCount & sNextLine
   lLineCount = lLineCount + 1
Loop
Text1.Text = sText
Text2.Text = lLineCount - 1
Text3.Text = sNextLine

' Close the file
Close nFileNum

End Sub



I see that it gives me the baseline but I need someone to help me to modify it so that it stores strings, as I know how to set data into a string, I need it to, upon clicking save, save a series of strings within the coding of the form, and then upon clicking open, load various strings into variables, which I can do so long as I get a proper reading system set up, another thing I need help with... but I need it to save the strings to clear variables within a text file, and upon clicking the open button, I need it to read and load those strings back into more strings within the program... so anyone that knows how to do this please help me out...


I'm making a role playing game in visual basic 6. some of the strings will include things like: experience, health, max_health, user-name, password, and things like that, those are a few things I need saved into a text file, which I have a common dialog set up to save the name of the file, and I need to be able to save them as clearly marked data sets... like if it is possible to have a copy of the variables and their values within the file, then all the better...

Is This A Good Question/Topic? 0
  • +

Replies To: save and open button in vb6 for rpg

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: save and open button in vb6 for rpg

Posted 05 March 2010 - 04:22 PM

hello :)

i will show you how i do it :)
Option Explicit
'a structure(type) that holds the string we input/read from the file'
Private Type My_String_Sturct
    string1 As String
    string2 As String
    string3 As String
End Type

Private m_ As My_String_Sturct

Private Sub cmdOpen_Click()
'open the file and fill the textboxes'
    Open "c:\test.txt" For Binary As #1
        Get #1, , m_     'Read the file'
    Close 1
    Text1.Text = m_.string1
    Text2.Text = m_.string2
    Text3.Text = m_.string3
End Sub

Private Sub cmdSave_Click()
'open the file and save the variables in the file'
    m_.string1 = "SomeText1"
    m_.string2 = "SomeText2"
    m_.string3 = "SomeText3"
    
    Open "c:\test.txt" For Binary As #1
    Put #1, , m_
    Close 1
    
End Sub



so what we do is create a structure(type) and we put in it the variables that we read or save into the text file. i dim m_ as the structure for easy use(it is short :P ). then in the save button click event we input some values in the each variable then open the text file and using Put we put the whole structure in the file. that way when we open the file in the open button click event we can put the whole file in the structure. as you see if you add this buttons and 3 textboxes the file is loaded in the same variable as they are put and they are display in the textboxes.

good luck dude :)

This post has been edited by NoBrain: 05 March 2010 - 04:24 PM

Was This Post Helpful? 1
  • +
  • -

#3 mapmd1234  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 147
  • Joined: 04-December 09

Re: save and open button in vb6 for rpg

Posted 05 March 2010 - 05:00 PM

View PostNoBrain, on 05 March 2010 - 03:22 PM, said:

hello :)

i will show you how i do it :)
Option Explicit
'a structure(type) that holds the string we input/read from the file'
Private Type My_String_Sturct
    string1 As String
    string2 As String
    string3 As String
End Type

Private m_ As My_String_Sturct

Private Sub cmdOpen_Click()
'open the file and fill the textboxes'
    Open "c:\test.txt" For Binary As #1
        Get #1, , m_     'Read the file'
    Close 1
    Text1.Text = m_.string1
    Text2.Text = m_.string2
    Text3.Text = m_.string3
End Sub

Private Sub cmdSave_Click()
'open the file and save the variables in the file'
    m_.string1 = "SomeText1"
    m_.string2 = "SomeText2"
    m_.string3 = "SomeText3"
    
    Open "c:\test.txt" For Binary As #1
    Put #1, , m_
    Close 1
    
End Sub



so what we do is create a structure(type) and we put in it the variables that we read or save into the text file. i dim m_ as the structure for easy use(it is short :P ). then in the save button click event we input some values in the each variable then open the text file and using Put we put the whole structure in the file. that way when we open the file in the open button click event we can put the whole file in the structure. as you see if you add this buttons and 3 textboxes the file is loaded in the same variable as they are put and they are display in the textboxes.

good luck dude :)

thank you very much nobrain... i will take this and experiment with it to see how it works and get back with you... but thank you very much and i will need some of that luck...lol... but thanks once again. ^^

when i run the program it says that the path is not found... so what do i need to change to have it create the file...as that is the step im am at...i need it to actually create the file with the atributes at the time that they press the CMDsave_onclick() i need it to actually create the file...thanks again...

This post has been edited by mapmd1234: 05 March 2010 - 05:34 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1