473,472 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How Do I Save Things With Vb 6 (At Runtime)

12 New Member
Ok, well ive made a simple little message box creator. What it does it lets you change the caption the header the buttons and the warning type of a message box. I now want to make it so if you want, you can save the message box youve just created. I have no idea how to do this, keep in mind im still a noob here is a sample of my code so you can see what level im at. (I would prefer it if you could show me how in terms that i would be able to understand.)

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCreate_Click()
  2.     strMessageBoxText = Text2.Text
  3.     strMessageBoxHeader = Text1.Text
  4.  
  5.     Debug.Print "Combo1.Text = "; Combo2.Text
  6.  
  7.  
  8.     If Combo1.Text = "Critical" Then
  9.         strAlertType = 16
  10.     ElseIf Combo1.Text = "Exclamation" Then
  11.         strAlertType = 48
  12.     ElseIf Combo1.Text = "Information" Then
  13.         strAlertType = 64
  14.     ElseIf Combo1.Text = "Question" Then
  15.         strAlertType = 32
  16.     End If
  17.  
  18.     If Combo2.Text = "Ok" Then
  19.         strButtonCombo = 0
  20.     ElseIf Combo2.Text = "Ok, Cancel" Then
  21.         strButtonCombo = 1
  22.     ElseIf Combo2.Text = "Yes, No" Then
  23.         strButtonCombo = 4
  24.     ElseIf Combo2.Text = "Yes, No, Cancel" Then
  25.         strButtonCombo = 3
  26.     ElseIf Combo2.Text = "Abort, Retry, Ignore" Then
  27.         strButtonCombo = 2
  28.     ElseIf Combo2.Text = "Retry, Cancel" Then
  29.         strButtonCombo = 5
  30.     End If
  31.  
  32.     strMessageBox = MsgBox(strMessageBoxText, strAlertType + strButtonCombo, strMessageBoxHeader)
  33.  
  34.     If strMessageBox = vbRetry Then
  35.         Do
  36.          strMessageBox = MsgBox(strMessageBoxText, strAlertType + strButtonCombo, strMessageBoxHeader)
  37.         Loop While strMessageBox <> vbAbort And strMessageBox <> vbIgnore And strMessageBox <> vbCancel
  38.     End If
  39.  
  40.  
  41.     strTest = MsgBox("Want to do a more advanced test?", vbQuestion + vbYesNo, "More Advanced Test")
  42.     If strTest = vbYes Then
  43.         frmMessageBoxCreator.Hide
  44.         strMessageBox = MsgBox(strMessageBoxText, strAlertType + strButtonCombo, strMessageBoxHeader)
  45.         If strMessageBox = vbRetry Then
  46.         Do
  47.          strMessageBox = MsgBox(strMessageBoxText, strAlertType + strButtonCombo, strMessageBoxHeader)
  48.         Loop While strMessageBox <> vbAbort And strMessageBox <> vbIgnore And strMessageBox <> vbCancel
  49.     End If
  50.         frmMessageBoxCreator.Show
  51.     End If
  52.     Debug.Print "Combo1.Text"; Combo2.Text
  53.  
Oh BTW ive named the 2 variables for alert type and button combos as "str..."
thats because at first they were strings but then i changed the values to numbers instead of "vbCritical" or "vbYesNo"


Thanks,

HaggardSmurf
Oct 29 '06 #1
13 3819
Killer42
8,435 Recognized Expert Expert
Hi.

Just a couple of pointers, that might be some help.
  • You can easily rename the variables by doing a Replace, the same as in Word, Excel or whatever. While in the code window, just press Ctrl-H or select Edit|Replace.
  • At a very simple level, you can write out your values to a text file and read them back in each time you start the program. For instance, something like
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cmdSave_Click()
    2. Open "Settings.txt" For Output Access Write Lock Read Write As #1
    3. Print #1, strMessageBoxText
    4. Print #1, strAlertType
    5. Print #1, strButtonCombo
    6. Print #1, strMessageBoxHeader
    7. Close #1
    8. End Sub
    Then at start-up (as an example I’ll use Form_Load procedure, but that may not fit what you’re doing) do this:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Load ()
    2. If Dir$("Settings.Txt") <> "" then  ' File exists, so read it...
    3.   Open "Settings.txt" For Input Access Read Shared As #1
    4.   Line Input #1, strMessageBoxText
    5.   Line Input #1, strAlertType
    6.   Line Input #1, strButtonCombo
    7.   Line Input #1, strMessageBoxHeader
    8.   Close #1
    9. End If
    10. End Sub
  • You could also save your settings in an INI file, or in the system registry.
Oct 30 '06 #2
HaggardSmurf
12 New Member
So, I would make it log the settings then how would i make it so when it opens it will show the previous message box.

Edit: I tried and it says Type Mismatch the variables are global and your variables are the same as i declared them.
Nov 1 '06 #3
Killer42
8,435 Recognized Expert Expert
So, I would make it log the settings then how would i make it so when it opens it will show the previous message box.

Edit: I tried and it says Type Mismatch the variables are global and your variables are the same as i declared them.
Well, the idea was that the proc I wrote (Form_Load in the example) would set up your variables the same way you had them set before. Then it's up to you to show your message box, the same way you are doing now, I suppose.
Nov 1 '06 #4
HaggardSmurf
12 New Member
Well, the idea was that the proc I wrote (Form_Load in the example) would set up your variables the same way you had them set before. Then it's up to you to show your message box, the same way you are doing now, I suppose.
Wait... What if i took your code and put it in a different exe's form load. Then that will load the previous settings. Would that work? If i did that how would i make the exe search wherever it is for the text document.

Ex: I have a folder called messagebox creator. Both exe's are inside. I make a message box. I save the message box. I boot up the 2nd exe. How would it know to look in the folder that the 2nd exe itself is located in for the text document? Cause what i want to do is make it sendable so people can prank their friends. In order for it to be a good prank you need to be able to change the exe's name and folder name. No need to change the text document cause it will be invisible
Nov 4 '06 #5
Killer42
8,435 Recognized Expert Expert
Wait... What if i took your code and put it in a different exe's form load. Then that will load the previous settings. Would that work? If i did that how would i make the exe search wherever it is for the text document.

Ex: I have a folder called messagebox creator. Both exe's are inside. I make a message box. I save the message box. I boot up the 2nd exe. How would it know to look in the folder that the 2nd exe itself is located in for the text document? Cause what i want to do is make it sendable so people can prank their friends. In order for it to be a good prank you need to be able to change the exe's name and folder name. No need to change the text document cause it will be invisible
You might want to have a look in the VB doco for info on file access, specifically with regard to specifying the path. But the short version is, if you specify just the file name (Settings.txt in the example) then it will look in the "current" directory. That will usually be where the Exe was, but can change depending on how you do things. For instance, when you create a shortcut in Windows to run an Exe you can specify where to load it from, and what directory to run in.
Nov 5 '06 #6
HaggardSmurf
12 New Member
You might want to have a look in the VB doco for info on file access, specifically with regard to specifying the path. But the short version is, if you specify just the file name (Settings.txt in the example) then it will look in the "current" directory. That will usually be where the Exe was, but can change depending on how you do things. For instance, when you create a shortcut in Windows to run an Exe you can specify where to load it from, and what directory to run in.

Oh i see, thanks i'll try making it and see what happens.
Nov 6 '06 #7
Killer42
8,435 Recognized Expert Expert
Oh i see, thanks i'll try making it and see what happens.
If you want, you can also specify the full path. For instance...
Expand|Select|Wrap|Line Numbers
  1. Open "C:\Temp\SomeFile.Txt" For Input Access Read Shared As #1
This line is quite inflexible, of course, but you can produce all sorts of variations on the theme.
Nov 6 '06 #8
HaggardSmurf
12 New Member
If you want, you can also specify the full path. For instance...
Expand|Select|Wrap|Line Numbers
  1. Open "C:\Temp\SomeFile.Txt" For Input Access Read Shared As #1
This line is quite inflexible, of course, but you can produce all sorts of variations on the theme.

Ok so ive found a different code that works and i seem to understand. Im on a new project now ;) im trying to save the contence of a list box this code works for me but is saving in the C:\ drive no directory which i wanted at first but now ive changed my mind and want it to save to the save folder as the exe. Ive tried saving to "\Ips.txt" and it didnt work.

*Btw this code is for an ip monitor it will monitor ip's trying to connect to you. My lame attempt at making a firewall :P

Anyways this is the code im using:
Expand|Select|Wrap|Line Numbers
  1. or i = 0 To LstSave.ListCount - 1
  2.         A(i) = LstSave.List(i)
  3.         Next i
  4.         ItemCount = LstSave.ListCount
  5.         Open "C:\Documents and Settings\YOUR USER DETAILS\Desktop\tempsave.txt" For Output As 1 'open the path to the text file to save data entries
  6.         For i = 0 To ItemCount - 1
  7.             Write #1, A(i) 'write to the text file the contents of listbox
  8.             Next i
  9.             Close #1
  10.  
Any suggestions on how to save to the current exe directory?
Nov 17 '06 #9
HaggardSmurf
12 New Member
Sorry i copied the wrong code.

This is my current code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.     Dim Save As String
  3. Open "\Ips.txt" For Output Access Write Lock Read Write As #1
  4.  
  5.         For i = 0 To List1.ListCount - 1
  6.         A(i) = List1.List(i)
  7.         Next i
  8.         ItemCount = List1.ListCount
  9.         For i = 0 To ItemCount - 1
  10.             Write #1, A(i) 'write to the text file the contents of listbox
  11.             Next i
  12.             Close #1
  13.  
Sry for the double post
Nov 17 '06 #10
Killer42
8,435 Recognized Expert Expert
This might work
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.     Dim Save As String
  3.     Open App.Path &  "\Ips.txt" For Output Access Write Lock Read Write As #1
  4.     For i = 0 To List1.ListCount - 1
  5.         A(i) = List1.List(i)
  6.     Next i
  7.     ItemCount = List1.ListCount
  8.     For i = 0 To ItemCount - 1
  9.         Write #1, A(i) 'write to the text file the contents of listbox
  10.     Next i
  11.     Close #1
  12.  
Nov 17 '06 #11
schandraram
5 New Member
So, I would make it log the settings then how would i make it so when it opens it will show the previous message box.

Edit: I tried and it says Type Mismatch the variables are global and your variables are the same as i declared them.
I know its way too long after your post... but this might be helpful to you later too ;-)

The message box constant is a number whereas when you use the Line Input statement, you are reading in a string. Convert this string into a number and the code should work.

Hope this helps
Chandra
Nov 17 '06 #12
HaggardSmurf
12 New Member
I know its way too long after your post... but this might be helpful to you later too ;-)

The message box constant is a number whereas when you use the Line Input statement, you are reading in a string. Convert this string into a number and the code should work.

Hope this helps
Chandra
Ohhh really? Cool i will try fixing that thank you!

This might work
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.     Dim Save As String
  3.     Open App.Path &  "\Ips.txt" For Output Access Write Lock Read Write As #1
  4.     For i = 0 To List1.ListCount - 1
  5.         A(i) = List1.List(i)
  6.     Next i
  7.     ItemCount = List1.ListCount
  8.     For i = 0 To ItemCount - 1
  9.         Write #1, A(i) 'write to the text file the contents of listbox
  10.     Next i
  11.     Close #1
  12.  
Awsome! I thought just putting the file location as "/Ips.txt" would make it so the text doccument would be placed in the same folder. I never knew about the function app.path.

Tested it and it works Thanks! ;)
Nov 18 '06 #13
Killer42
8,435 Recognized Expert Expert
Awsome! I thought just putting the file location as "/Ips.txt" would make it so the text doccument would be placed in the same folder. I never knew about the function app.path.
Sounds as though you need to take the time to understand better how paths work. Starting with a backslash indicates the root directory of the current drive. You can specify the whole or partial path. In this case, the App object provides a number of useful pieces of information, including the .Path property. I can never remember whether this indicates the path where the Exe lives, or the one where you ran it. But more often that not, they're the same thing.

Ironically, you might have got the same end result by leaving out the backslash. If you had just specified "Ips.txt" with no path it would have used the current directory - which may or may not have been the correct one.
Nov 19 '06 #14

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

Similar topics

14
by: wolftor | last post by:
1) Is there a free runtime version of Access available that is more recent than the one for Access 2000? 2) If I create an application (MDE) in A2K, will it run on all later versions of Access?...
7
by: TSanders | last post by:
Wize ones: I created an Access database for a local telco that is split into a front and back end. I would like to distribute the Access runtime along with the front end. When I use the front...
17
by: Karl Irvin | last post by:
To use the Textstream object, I had to set a Reference to the Microsoft Scripting Runtime. This works good with A2000 Is the Scripting Runtime included with A2002 and A2003 so the Reference...
2
by: EMW | last post by:
Hi, Is it possible to get the date on which the aspx file was created/last saved at runtime? rg, Eric
3
by: EricJ | last post by:
imagine having a fixed picture in a form, if the user clicks in the picture an x has to be displayed where the user clicked (so far not much problems). But the user can make as much x'ses as he...
2
by: PW | last post by:
Hi, What the heck is that supposed to mean? I am getting this error on a "Me.Requery" line in a subroutine on a form, but only when I select something from a combo/dropdown box. The *exact*...
5
by: kimtherkelsen | last post by:
Hi, I have made some software that uses one of the COM ports to communicate with an external device. The software is written in C# and uses the new SerialPort class in .Net 2.0. It works...
6
by: SMcK | last post by:
I have a PDA-based (Syware Visual CE) database which I need to sync to an Access database. The Access database contains three tables: 1 is the data itself, 2 is a linked table that prefills...
3
by: Don Barton | last post by:
Does anyone know if Tony Toews Auto FE updater utility work with the new Access 2007 Runtime? I am new to using the runtime, but have clients starting to ask for it. (they don't want to have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.