Digital Paint Discussion Board

Digital Paint Community => Other Stuff => Topic started by: Apocalypse on July 19, 2008, 05:55:58 PM

Title: More VB6 Help
Post by: Apocalypse on July 19, 2008, 05:55:58 PM
I have been making a program I use this code
Code: [Select]
Option Explicit
Dim msg As String
Dim dlgdef As String
Dim Caption As String

Private Sub cmdOK_Click()
    If txtusername.Text = Master Then
        If txtpassword.Text = M4573r5hip Then
            Load (frmAdmin.frm)
        Else
            msg = "Incorrect Password"
            dlgdef = "vbOKOnly"
            Caption = "Incorrect Password"
            MsgBox(msg, dlgdef, caption)
        End If
    Else
        msg = "Incorrect Username"
        dlgdef = "VbOKOnly"
        Caption = "Incorrect Username"
        MsgBox(msg, dlgdef, caption)
End Sub
When I edit something on the lines opening the message boxes and click on something else or go to a different line I get the error
Compile Error:
Expected: =
Any idea why I get this error?
Title: Re: More VB6 Help
Post by: sk89q on July 19, 2008, 08:27:44 PM
If M4573r5hip is a string, surround it in quotes.
If I recall correctly, vbOKOnly is a global constant, so you need to remove the quotes.
Title: Re: More VB6 Help
Post by: Apocalypse on July 19, 2008, 09:16:18 PM
Changed them but I still get that error.
Title: Re: More VB6 Help
Post by: IronFist on July 19, 2008, 11:50:41 PM
Changed them but I still get that error.

FREENODE MERCILESS NAZI MODE ACTIVE

Where's your book?
Title: Re: More VB6 Help
Post by: Eiii on July 20, 2008, 12:26:13 AM
It might help if you told us what line the error is on.
Title: Re: More VB6 Help
Post by: Krizdo4 on July 20, 2008, 12:44:01 AM
I have been making a program I use this code
Code: [Select]
Option Explicit
Dim msg As String
Dim dlgdef As String
Dim Caption As String

Private Sub cmdOK_Click()
    If txtusername.Text = Master Then
        If txtpassword.Text = M4573r5hip Then
            Load (frmAdmin.frm)
        Else
            msg = "Incorrect Password"
            dlgdef = "vbOKOnly"
            Caption = "Incorrect Password"
            MsgBox(msg, dlgdef, caption)
        End If
    Else
        msg = "Incorrect Username"
        dlgdef = "VbOKOnly"
        Caption = "Incorrect Username"
        MsgBox(msg, dlgdef, caption)
End Sub
When I edit something on the lines opening the message boxes and click on something else or go to a different line I get the error
Compile Error:
Expected: =
Any idea why I get this error?

Your error is on the MsgBox lines.
Because you're using ( ) after msgbox you must have a return value.
Do either of these:
1: Remove the ( ) e.g.
MsgBox(msg, dlgdef, caption)
into
MsgBox msg, dlgdef, caption

2. Add a variable to return a value to.
dim dummy
dummy = MsgBox(msg, dlgdef, caption)


You also need the " " around M4573r5hip  as already noted.
Oh and since this is on a form you can't use the name Caption for any of your variables since it's already a part of the form. (Window title)

edit:
As sk89q noted, vbOKOnly is a constant but not only do you need to remove the quotes but you should use the correct datatype for dlgdef which believe is integer, definitely not string. I might be a long but I doubt it.
Title: Re: More VB6 Help
Post by: Apocalypse on July 21, 2008, 08:47:54 AM
Thanks Krizdo I was looking through my book and noticed the no brackets and I figured out the caption thing just had no time to post. Not the string though that will save me lots of speed in big projects.
Offtopic: VB6 is the worst packaged program ever :/
Title: Re: More VB6 Help
Post by: ViciouZ on July 21, 2008, 09:12:57 AM
I have "Visual Basic 2.0 for Windows". It comes on 2 floppy disks.
Title: Re: More VB6 Help
Post by: Apocalypse on July 21, 2008, 03:00:01 PM
I have Visual Basic 6.0 comes with like 7 different cds :/
Title: Re: More VB6 Help
Post by: Eiii on July 21, 2008, 03:39:58 PM
VB just seems painful to work in. Seriously, why not C#? As far as I can tell it's almost exactly the same, but without hideously unreadable syntax.
Title: Re: More VB6 Help
Post by: Apocalypse on July 21, 2008, 03:54:03 PM
I've actually never tried C# before I should give it a try.
Title: Re: More VB6 Help
Post by: IronFist on July 21, 2008, 08:32:20 PM
I've actually never tried C# before I should give it a try.

Learning a .Net language is going to do you a lot better than VB6 if you plan to ever get serious about things. Especially C#, since the syntax itself is important to become familiar with early on, so that you can move to C/Java/all the other C-derived languages. I'm not personally much of a .Net fan (despite Mono, it's still locked to Windows pretty well), but it's pretty decent if you're going to use C#, and the API itself is plenty expansive. Don't bother with VB.Net; coming from VB6, you will just become very confused, since it has very little in common with VB6.

I personally feel that learning VB6 threw me off a year or two as far as learning. You can do pretty much anything you want with VB6, but you aren't going to actually learn much that will be useful outside of VB6 (the most I got out of it was network programming with the winsock OCX control).

Get a C# book or google for tutorials. This one looks pretty complete, while being somewhat brief (this may not be as good as a book, though):
http://www.csharp-station.com/Tutorial.aspx

Going over an entire book or tutorial now will save you a lot of trouble later.
Title: Re: More VB6 Help
Post by: Apocalypse on July 22, 2008, 10:35:25 AM
Thanks greatly appreciated I have programmed a very small amount in C++ but I never made anything very big with it.