Results 1 to 27 of 27

Thread: How do I make a customized message box

  1. #1

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131

    How do I make a customized message box

    I got it to work if I left out title and type
    VB Code:
    1. msgbox ("hello")
    but when I tried to add title and type
    VB Code:
    1. 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

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Loose the parens (), like:
    VB Code:
    1. 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.

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Here is when you can use the Parenthesis:
    VB Code:
    1. If MsgBox("You win", vbYesNo + vbExclamation, "Congrats") = vbYes Then MsgBox "Ok"




    bruce.

  4. #4

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    is it possible to Make your own Message box
    ';..;'
    Monsterous

    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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.

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Here is an example:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. 'This is on Form1
    5.     frmMyMessageBox.Caption = "Congratulations"
    6.     frmMyMessageBox.lblPrompt.Caption = "You Win!"
    7.     frmMyMessageBox.Show vbModal
    8. 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.

  7. #7

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    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

  8. #8
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Originally posted by SandmanSamR
    text box for a hangman program
    TextBox or TextFile?


    The TextFile would be simple enough.

  9. #9

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    , thats what I meant. A text file thats is on my harddrive.
    ';..;'
    Monsterous

    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR

  10. #10
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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.

  11. #11

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    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

  12. #12

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    the file is set up like this:
    cow
    sheep
    car

    and its a *.txt file
    ';..;'
    Monsterous

    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR

  13. #13
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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.

  14. #14

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    load the TextFile into an Array

    the way I loaded it was just:
    VB Code:
    1. Private Sub Form_load()
    2. Open "A:\Words.txt" For Input As #1
    3. Input #1, word

    What do I change that to?
    ';..;'
    Monsterous

    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR

  15. #15

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    Whats this part for:

    VB Code:
    1. Err_Handler:
    2.     MsgBox "Number: " & Err.Number & vbCrLf & _
    3.     "Description: " & Err.Description, vbOKOnly + vbInformation, "File I/O Error"
    ';..;'
    Monsterous

    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR

  16. #16
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by SandmanSamR
    Whats this part for:

    VB Code:
    1. Err_Handler:
    2.     MsgBox "Number: " & Err.Number & vbCrLf & _
    3.     "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 .

  17. #17
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Oops, sorry... the Array sould be loaded when the Form Loads (not each time the button is pressed):
    VB Code:
    1. Option Explicit
    2.  
    3. 'Rnd use: Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
    4.  
    5. Dim strArr() As String
    6.  
    7. Private Sub Form_Load()
    8.  
    9. On Error GoTo Err_Handler
    10.  
    11.     'Open and load the Array with the Text File
    12.     Open "C:\HangmanWords.txt" For Input As #1
    13.         strArr = Split(Input(LOF(1), 1), vbCrLf)
    14.     Close #1
    15.  
    16. Exit Sub
    17.  
    18. Err_Handler:
    19.     MsgBox "Number: " & Err.Number & vbCrLf & _
    20.     "Description: " & Err.Description, vbOKOnly + vbInformation, "File I/O Error"
    21. End Sub
    22.  
    23. Private Sub Command1_Click()
    24.  
    25.     'Now the TextFile is loaded, pick a random word
    26.     Randomize
    27.  
    28.     MsgBox strArr(Int((UBound(strArr) - LBound(strArr) + 1) * Rnd + LBound(strArr)))
    29.  
    30. End Sub




    bruce.

  18. #18

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    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

  19. #19
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    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 .

  20. #20

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    buggy, check that last thing i wrote. teh edit
    ';..;'
    Monsterous

    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR

  21. #21

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    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

  22. #22
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Post your code.

    (and I had redone the code too - the correct version is may inediate last post )

  23. #23

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    VB Code:
    1. Dim y As Integer
    2. Dim mistakes As Integer
    3. Dim found As Integer
    4. Dim word As String
    5. Dim x As Integer
    6. Dim correcttotal As Integer
    7. Dim d
    8. Option Explicit
    9.  
    10. Private Sub cmdprob49_click(index As Integer)
    11. cmdProb49(index).Visible = False
    12. found = 0
    13.  
    14. y = 1
    15. While y <= x
    16. If Mid(word, y, 1) = cmdProb49(index).Caption Then
    17. Label1(y - 1).Caption = cmdProb49(index).Caption
    18. found = 1
    19. correcttotal = correcttotal + 1
    20. End If
    21. y = y + 1
    22. Wend
    23. If found = 0 Then
    24. mistakes = mistakes + 1
    25. If mistakes = 1 Then
    26. Shape1.Visible = True
    27. End If
    28. If mistakes = 2 Then
    29. Line3.Visible = True
    30. End If
    31. If mistakes = 3 Then
    32. Line6.Visible = True
    33. End If
    34. If mistakes = 4 Then
    35. Line7.Visible = True
    36. End If
    37. If mistakes = 5 Then
    38. Line4.Visible = True
    39. End If
    40. If mistakes = 6 Then
    41. Line5.Visible = True
    42. End If
    43. End If
    44. found = 0
    45.  
    46. If correcttotal = Len(word) Then
    47. MsgBox "You win", vbExclamation = vbOKOnly, "Congrats"
    48. End If
    49.  
    50. End Sub
    51. Private Sub Form_load()
    52. Open "A:\Words.txt" For Input As #1
    53. Input #1, word
    54.  
    55. x = Len(word)
    56. y = x
    57. While y <= 6
    58. Label1(y).Visible = False
    59. y = y + 1
    60. Wend
    61. correcttotal = 0
    62. End Sub
    ';..;'
    Monsterous

    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR

  24. #24
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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!

  25. #25

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    how do I get it so that your second point is random
    ';..;'
    Monsterous

    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR
    SANDMANSAMR

  26. #26

    Thread Starter
    Addicted Member SandmanSamR's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    131
    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

  27. #27
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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:
    1. Option Explicit
    2.  
    3. Dim strArr() As String
    4.  
    5. Private Sub Form_Load()
    6.  
    7. On Error GoTo Err_Handler
    8.  
    9.     'Open and load the Array with the Text File
    10.     Open "C:\HangmanWords.txt" For Input As #1
    11.         strArr = Split(Input(LOF(1), 1), vbCrLf)
    12.     Close #1
    13.  
    14. Exit Sub
    15.  
    16. Err_Handler:
    17.     MsgBox "Number: " & Err.Number & vbCrLf & _
    18.     "Description: " & Err.Description, vbOKOnly + vbInformation, "File I/O Error"
    19. End Sub
    20.  
    21. Private Sub Command1_Click()
    22.  
    23.     'Now the TextFile is loaded, pick a random word
    24.     Randomize
    25.  
    26.     MsgBox strArr(Int((UBound(strArr) - LBound(strArr) + 1) * Rnd + LBound(strArr)))
    27.  
    28. 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
  •  



Click Here to Expand Forum to Full Width