|
-
Jan 14th, 2004, 08:18 PM
#1
Thread Starter
Addicted Member
How do I make a customized message box
I got it to work if I left out title and type
but when I tried to add title and type
VB Code:
MsgBox("You win", vbExclamation = vbOKOnly, "Congrats")
it said "compile error: Epected: =". Why is that comming up? After the hassel I just gave up and wanted to know, can I get it so I can put whatever message in the caption of the button or do I have to do an imitation and make a small for that looks like a msgbox?
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 08:20 PM
#2
Loose the parens (), like:
VB Code:
MsgBox "You win", vbOKOnly + vbExclamation, "Congrats"
If you want the MsgBox to return (eg. vbYes/vbNo) then you can use the Parenthesis.
Edit: Note the use of "+" inplace of the "=". And you typacilly have the vbOk, vbOkOnly etc prior to the icon (Exclamation/Caution etc)
Bruce.
Last edited by Bruce Fox; Jan 14th, 2004 at 08:29 PM.
-
Jan 14th, 2004, 08:26 PM
#3
Here is when you can use the Parenthesis:
VB Code:
If MsgBox("You win", vbYesNo + vbExclamation, "Congrats") = vbYes Then MsgBox "Ok"
bruce.
-
Jan 14th, 2004, 08:29 PM
#4
Thread Starter
Addicted Member
is it possible to Make your own Message box
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 08:48 PM
#5
Certanly; create one using a Form! Add an "Ok" command Button and show the Form as Modal. That way the user MUST click on of the CommandButtons on the form. In other words, the Form (in this case your MessageBox) will retain the focus.
(Alternatly, you could Sub-Class the Windows MessageBox - althought that probably isn't something you want to deal with at the moment)
Bruce.
-
Jan 14th, 2004, 08:55 PM
#6
Here is an example:
VB Code:
Option Explicit
Private Sub Command1_Click()
'This is on Form1
frmMyMessageBox.Caption = "Congratulations"
frmMyMessageBox.lblPrompt.Caption = "You Win!"
frmMyMessageBox.Show vbModal
End Sub
Add a another Form, and call it frmMyMessageBox. Place a Label on it named lblPrompt (add a picture too if you like).
Then on the (main) Form, envoke your MessageBox as above (I used a CommandButton to pop up the MyMessageBox).
Bruce.
-
Jan 14th, 2004, 08:57 PM
#7
Thread Starter
Addicted Member
got it. The last part of the code I would rather try for another hour or so before I ask. Although I'm not sure how the hell to do it. I got to pull a random word from a text box for a hangman program
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 09:01 PM
#8
Originally posted by SandmanSamR
text box for a hangman program
TextBox or TextFile?
The TextFile would be simple enough.
-
Jan 14th, 2004, 09:02 PM
#9
Thread Starter
Addicted Member
, thats what I meant. A text file thats is on my harddrive.
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 09:04 PM
#10
What is the structure of the TextFile ( )? Is it comma deliniated?
Are the words seperated by spaces...... etc?
Maybe post a snippet of the TextFile.
Bruce.
-
Jan 14th, 2004, 09:04 PM
#11
Thread Starter
Addicted Member
they got a lot of people working on the "hangman" program on these boards over the time. Problem is that the links to where my solution is are all broken links and I tried everything I could. My teacher wrote it on the board but I didnt think I would get this far on one night (I had a ton of other things to do)
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 09:05 PM
#12
Thread Starter
Addicted Member
the file is set up like this:
cow
sheep
car
and its a *.txt file
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 09:08 PM
#13
I would load the TextFile into an Array (using Split with the Carriage return as the delimiter) and the randomly pick an Array Elemnt
(which of course now contains a Word).
The advantage of loading the Array is that you only need to open the TextFile once (reduce File I/O),
and the Array is loaded for additional new games.
I'll knock something up.
-
Jan 14th, 2004, 09:10 PM
#14
Thread Starter
Addicted Member
load the TextFile into an Array
the way I loaded it was just:
VB Code:
Private Sub Form_load()
Open "A:\Words.txt" For Input As #1
Input #1, word
What do I change that to?
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 09:17 PM
#15
Thread Starter
Addicted Member
Whats this part for:
VB Code:
Err_Handler:
MsgBox "Number: " & Err.Number & vbCrLf & _
"Description: " & Err.Description, vbOKOnly + vbInformation, "File I/O Error"
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 09:19 PM
#16
The picture isn't missing
Originally posted by SandmanSamR
Whats this part for:
VB Code:
Err_Handler:
MsgBox "Number: " & Err.Number & vbCrLf & _
"Description: " & Err.Description, vbOKOnly + vbInformation, "File I/O Error"
if the file does not exists or some other error, it will go to that part and tell you, instead of crashing the program.
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jan 14th, 2004, 09:19 PM
#17
Oops, sorry... the Array sould be loaded when the Form Loads (not each time the button is pressed):
VB Code:
Option Explicit
'Rnd use: Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Dim strArr() As String
Private Sub Form_Load()
On Error GoTo Err_Handler
'Open and load the Array with the Text File
Open "C:\HangmanWords.txt" For Input As #1
strArr = Split(Input(LOF(1), 1), vbCrLf)
Close #1
Exit Sub
Err_Handler:
MsgBox "Number: " & Err.Number & vbCrLf & _
"Description: " & Err.Description, vbOKOnly + vbInformation, "File I/O Error"
End Sub
Private Sub Command1_Click()
'Now the TextFile is loaded, pick a random word
Randomize
MsgBox strArr(Int((UBound(strArr) - LBound(strArr) + 1) * Rnd + LBound(strArr)))
End Sub
bruce.
-
Jan 14th, 2004, 09:20 PM
#18
Thread Starter
Addicted Member
The code you gave me just made it so that when I click any letter it says I win. On top of that When I start it it yells at me and tells me to "MOVE"
Edit: Apperently it wasnt telling me to move, it was telling me in a msgbox what the word is... Ummm how do I make it not do that
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 09:22 PM
#19
The picture isn't missing
Originally posted by SandmanSamR
The code you gave me just made it so that when I click any letter it says I win. On top of that When I start it it yells at me and tells me to "MOVE"
make sure that the file C:\HangmanWords.txt actually exists. You could change the path to a valid file.
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jan 14th, 2004, 09:23 PM
#20
Thread Starter
Addicted Member
buggy, check that last thing i wrote. teh edit
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 09:26 PM
#21
Thread Starter
Addicted Member
its not adding any word now. It see's the variable word as "" instead of the first word in a:\words.txt
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 09:28 PM
#22
Post your code.
(and I had redone the code too - the correct version is may inediate last post )
-
Jan 14th, 2004, 09:29 PM
#23
Thread Starter
Addicted Member
VB Code:
Dim y As Integer
Dim mistakes As Integer
Dim found As Integer
Dim word As String
Dim x As Integer
Dim correcttotal As Integer
Dim d
Option Explicit
Private Sub cmdprob49_click(index As Integer)
cmdProb49(index).Visible = False
found = 0
y = 1
While y <= x
If Mid(word, y, 1) = cmdProb49(index).Caption Then
Label1(y - 1).Caption = cmdProb49(index).Caption
found = 1
correcttotal = correcttotal + 1
End If
y = y + 1
Wend
If found = 0 Then
mistakes = mistakes + 1
If mistakes = 1 Then
Shape1.Visible = True
End If
If mistakes = 2 Then
Line3.Visible = True
End If
If mistakes = 3 Then
Line6.Visible = True
End If
If mistakes = 4 Then
Line7.Visible = True
End If
If mistakes = 5 Then
Line4.Visible = True
End If
If mistakes = 6 Then
Line5.Visible = True
End If
End If
found = 0
If correcttotal = Len(word) Then
MsgBox "You win", vbExclamation = vbOKOnly, "Congrats"
End If
End Sub
Private Sub Form_load()
Open "A:\Words.txt" For Input As #1
Input #1, word
x = Len(word)
y = x
While y <= 6
Label1(y).Visible = False
y = y + 1
Wend
correcttotal = 0
End Sub
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 09:49 PM
#24
2 points:
1. The MsgBox "You win", vbExclamation = vbOKOnly, "Congrats" should be
MsgBox "You win", vbOKOnly + vbExclamation, "Congrats" as I previously pointed out.
And
2. The way your loading your textfile it will always load the First word in the TextFile!
-
Jan 14th, 2004, 09:50 PM
#25
Thread Starter
Addicted Member
how do I get it so that your second point is random
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 10:00 PM
#26
Thread Starter
Addicted Member
If you can easily do it then thats good. If its any problem just leave it, i'll see if I can get help from someone. Im tired, Im going to sleep
';..;'
Monsterous
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
SANDMANSAMR
-
Jan 14th, 2004, 10:14 PM
#27
I have done it.... I'll repost it.
To see how this works open a new projct add commandbutton, place the .txt file in C drive:
VB Code:
Option Explicit
Dim strArr() As String
Private Sub Form_Load()
On Error GoTo Err_Handler
'Open and load the Array with the Text File
Open "C:\HangmanWords.txt" For Input As #1
strArr = Split(Input(LOF(1), 1), vbCrLf)
Close #1
Exit Sub
Err_Handler:
MsgBox "Number: " & Err.Number & vbCrLf & _
"Description: " & Err.Description, vbOKOnly + vbInformation, "File I/O Error"
End Sub
Private Sub Command1_Click()
'Now the TextFile is loaded, pick a random word
Randomize
MsgBox strArr(Int((UBound(strArr) - LBound(strArr) + 1) * Rnd + LBound(strArr)))
End Sub
Bruce.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|