By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,871 Members | 2,464 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,871 IT Pros & Developers. It's quick & easy.

How do I recall a value added when I re-open my EXE?

AsSeenonTV
P: 2
Hey there! I will admit I am new to these Message Boards and to Visual Basic 6, but I am an experienced programmer when it comes to Visual Basic for Excel.

Now with working with Excel, I am able to save an input (to a cell) and recall it back to the userform when I re-open that Excel project. Now I'm working on a new project that I can take anywhere (without having Microsoft Office loaded on the computer).

Here's what I am trying to accomplish:

I am trying to make an Inventory List for an online game that I play. When I receive new items, I want to add it to the form (manually, via a text box) and update the program to include the new value. When I close and reopen my EXE for my inventory and select the item, I want the updated value to appear in a Label.

Here's the Code for the current project I have: The first Combo Box contains the type of items and the second Combo Box contains the actual Item names. In helping me, you can preserve the list names I have provided for the code.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Combo1.Clear
  3. Combo2.Clear
  4.  
  5. Combo1.AddItem ("Item 1")
  6. Combo1.AddItem ("item 2")
  7. Combo1.AddItem ("Item Three")
  8. Combo1.AddItem ("iTeM IV")
  9.  
  10. End Sub
  11.  
  12. Private Sub Combo1_Click()
  13. If Combo1.Text = "Item 1" Then
  14. Combo2.Clear
  15. Combo2.AddItem ("Sub-Item 1")
  16. Combo2.AddItem ("sub-item 2")
  17. Combo2.AddItem ("sub-item 3")
  18. Else
  19. If Combo1.Text = "item 2" Then
  20. Combo2.Clear
  21. Combo2.AddItem ("Sub-Item 4")
  22. Combo2.AddItem ("sub-item 5")
  23. Combo2.AddItem ("sub-item 6")
  24. Combo2.AddItem ("Sub-Item 7")
  25. Combo2.AddItem ("sub-item 8")
  26. Combo2.AddItem ("sub-item 9")
  27. End If
  28. End If
  29. End Sub
  30. Private Sub combo2_click()
  31. If Combo2.Text = "Sub-Item 1" Then
  32. Text1.Text = 23
  33. Else
  34. Text1.Text = ""
  35. End If
  36. End Sub
  37.  
Thank you all for your assistance!
Apr 22 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 5K+
P: 8,434
I'd say there are two main options for saving and restoring your data.
  1. Write the info out to a file (just a simple text file will do) before exiting (or each time the info changes). Read the file in when your program starts.
  2. Store it to the registry. This is relatively simple in VB6 and later.
Hm... on second thought, the latter would be useless if you want to carry the data with you, as well as the program. Probably best to stick with the former.

The simpler way to deal with a text file is by using the built-in keywords Open, Close, Print #, Input # and so on. The FileSystemObject object provides considerably more functionality, but is (only slightly) more complex to work with and requires you to add a reference (Microsoft Scripting Runtime) to your project.
Apr 23 '07 #2

AsSeenonTV
P: 2
Well, If that is the case, then I shall do all my inventory updating from my home computer, or load a copy of Office onto my work computer. That seems a bit too expert for me to use at my current knowledge level of Visual Basic 6. I will play around with VB6 until I feel comfortable coming back to this subject and trying my luck again at accomplishing what I am trying to do.

Thank you anyways for your assistance, Killer42!!
Apr 23 '07 #3

Expert 5K+
P: 8,434
Well, If that is the case, then I shall do all my inventory updating from my home computer, or load a copy of Office onto my work computer. That seems a bit too expert for me to use at my current knowledge level of Visual Basic 6. I will play around with VB6 until I feel comfortable coming back to this subject and trying my luck again at accomplishing what I am trying to do.

Thank you anyways for your assistance, Killer42!!
Fair enough.

I should point out, though, that using a text file via the Open/Close and so on is very simple. For example, let's say you just want to store the string variable strMyString into text file "MyFile.txt". You can do it in three lines...
Expand|Select|Wrap|Line Numbers
  1. OPEN "MyFile.txt" For Output Access Read Write Lock Write As #1
  2. Print #1, strMyString
  3. Close #1
And to read it back later...
Expand|Select|Wrap|Line Numbers
  1. OPEN "MyFile.txt" For Input Access Read Shared As #1
  2. Line Input #1, strMyString
  3. Close #1
Actually, I tend to be a bit long-winded with my options on the open. A lot of people leave most of them as default. So you could probably code something even simpler, such as (untested)...
Expand|Select|Wrap|Line Numbers
  1. OPEN "MyFile.txt" As #1
  2. Print #1, strMyString
  3. Close #1
If you check the doco, it'll tell you which parts are optional.
Apr 23 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.