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.) -
Private Sub cmdCreate_Click()
-
strMessageBoxText = Text2.Text
-
strMessageBoxHeader = Text1.Text
-
-
Debug.Print "Combo1.Text = "; Combo2.Text
-
-
-
If Combo1.Text = "Critical" Then
-
strAlertType = 16
-
ElseIf Combo1.Text = "Exclamation" Then
-
strAlertType = 48
-
ElseIf Combo1.Text = "Information" Then
-
strAlertType = 64
-
ElseIf Combo1.Text = "Question" Then
-
strAlertType = 32
-
End If
-
-
If Combo2.Text = "Ok" Then
-
strButtonCombo = 0
-
ElseIf Combo2.Text = "Ok, Cancel" Then
-
strButtonCombo = 1
-
ElseIf Combo2.Text = "Yes, No" Then
-
strButtonCombo = 4
-
ElseIf Combo2.Text = "Yes, No, Cancel" Then
-
strButtonCombo = 3
-
ElseIf Combo2.Text = "Abort, Retry, Ignore" Then
-
strButtonCombo = 2
-
ElseIf Combo2.Text = "Retry, Cancel" Then
-
strButtonCombo = 5
-
End If
-
-
strMessageBox = MsgBox(strMessageBoxText, strAlertType + strButtonCombo, strMessageBoxHeader)
-
-
If strMessageBox = vbRetry Then
-
Do
-
strMessageBox = MsgBox(strMessageBoxText, strAlertType + strButtonCombo, strMessageBoxHeader)
-
Loop While strMessageBox <> vbAbort And strMessageBox <> vbIgnore And strMessageBox <> vbCancel
-
End If
-
-
-
strTest = MsgBox("Want to do a more advanced test?", vbQuestion + vbYesNo, "More Advanced Test")
-
If strTest = vbYes Then
-
frmMessageBoxCreator.Hide
-
strMessageBox = MsgBox(strMessageBoxText, strAlertType + strButtonCombo, strMessageBoxHeader)
-
If strMessageBox = vbRetry Then
-
Do
-
strMessageBox = MsgBox(strMessageBoxText, strAlertType + strButtonCombo, strMessageBoxHeader)
-
Loop While strMessageBox <> vbAbort And strMessageBox <> vbIgnore And strMessageBox <> vbCancel
-
End If
-
frmMessageBoxCreator.Show
-
End If
-
Debug.Print "Combo1.Text"; Combo2.Text
-
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
13 3819
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
-
Private Sub cmdSave_Click()
-
Open "Settings.txt" For Output Access Write Lock Read Write As #1
-
Print #1, strMessageBoxText
-
Print #1, strAlertType
-
Print #1, strButtonCombo
-
Print #1, strMessageBoxHeader
-
Close #1
-
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: -
Private Sub Form_Load ()
-
If Dir$("Settings.Txt") <> "" then ' File exists, so read it...
-
Open "Settings.txt" For Input Access Read Shared As #1
-
Line Input #1, strMessageBoxText
-
Line Input #1, strAlertType
-
Line Input #1, strButtonCombo
-
Line Input #1, strMessageBoxHeader
-
Close #1
-
End If
-
End Sub
- You could also save your settings in an INI file, or in the system registry.
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.
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.
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
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.
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.
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... - 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.
If you want, you can also specify the full path. For instance... - 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: -
or i = 0 To LstSave.ListCount - 1
-
A(i) = LstSave.List(i)
-
Next i
-
ItemCount = LstSave.ListCount
-
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
-
For i = 0 To ItemCount - 1
-
Write #1, A(i) 'write to the text file the contents of listbox
-
Next i
-
Close #1
-
Any suggestions on how to save to the current exe directory?
Sorry i copied the wrong code.
This is my current code -
Private Sub Form_Unload(Cancel As Integer)
-
Dim Save As String
-
Open "\Ips.txt" For Output Access Write Lock Read Write As #1
-
-
For i = 0 To List1.ListCount - 1
-
A(i) = List1.List(i)
-
Next i
-
ItemCount = List1.ListCount
-
For i = 0 To ItemCount - 1
-
Write #1, A(i) 'write to the text file the contents of listbox
-
Next i
-
Close #1
-
Sry for the double post
This might work -
Private Sub Form_Unload(Cancel As Integer)
-
Dim Save As String
-
Open App.Path & "\Ips.txt" For Output Access Write Lock Read Write As #1
-
For i = 0 To List1.ListCount - 1
-
A(i) = List1.List(i)
-
Next i
-
ItemCount = List1.ListCount
-
For i = 0 To ItemCount - 1
-
Write #1, A(i) 'write to the text file the contents of listbox
-
Next i
-
Close #1
-
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
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 -
Private Sub Form_Unload(Cancel As Integer)
-
Dim Save As String
-
Open App.Path & "\Ips.txt" For Output Access Write Lock Read Write As #1
-
For i = 0 To List1.ListCount - 1
-
A(i) = List1.List(i)
-
Next i
-
ItemCount = List1.ListCount
-
For i = 0 To ItemCount - 1
-
Write #1, A(i) 'write to the text file the contents of listbox
-
Next i
-
Close #1
-
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! ;)
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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?...
|
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...
|
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...
|
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
|
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...
|
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*...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |