Author Topic: More VB6 Help  (Read 3137 times)

Apocalypse

  • Autococker
  • Posts: 1463
More VB6 Help
« on: July 19, 2008, 03: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?

sk89q

  • Global Moderator
  • Autococker
  • Posts: 1049
Re: More VB6 Help
« Reply #1 on: July 19, 2008, 06: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.

Apocalypse

  • Autococker
  • Posts: 1463
Re: More VB6 Help
« Reply #2 on: July 19, 2008, 07:16:18 PM »
Changed them but I still get that error.

IronFist

  • Autococker
  • Posts: 1304
Re: More VB6 Help
« Reply #3 on: July 19, 2008, 09:50:41 PM »
Changed them but I still get that error.

FREENODE MERCILESS NAZI MODE ACTIVE

Where's your book?

Eiii

  • Autococker
  • Posts: 4595
Re: More VB6 Help
« Reply #4 on: July 19, 2008, 10:26:13 PM »
It might help if you told us what line the error is on.

Krizdo4

  • PGP
  • Posts: 43
Re: More VB6 Help
« Reply #5 on: July 19, 2008, 10:44:01 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?

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.
« Last Edit: July 20, 2008, 12:14:54 AM by Krizdo4 »

Apocalypse

  • Autococker
  • Posts: 1463
Re: More VB6 Help
« Reply #6 on: July 21, 2008, 06: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 :/

ViciouZ

  • Map Committee
  • Autococker
  • Posts: 2227
Re: More VB6 Help
« Reply #7 on: July 21, 2008, 07:12:57 AM »
I have "Visual Basic 2.0 for Windows". It comes on 2 floppy disks.

Apocalypse

  • Autococker
  • Posts: 1463
Re: More VB6 Help
« Reply #8 on: July 21, 2008, 01:00:01 PM »
I have Visual Basic 6.0 comes with like 7 different cds :/

Eiii

  • Autococker
  • Posts: 4595
Re: More VB6 Help
« Reply #9 on: July 21, 2008, 01: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.

Apocalypse

  • Autococker
  • Posts: 1463
Re: More VB6 Help
« Reply #10 on: July 21, 2008, 01:54:03 PM »
I've actually never tried C# before I should give it a try.

IronFist

  • Autococker
  • Posts: 1304
Re: More VB6 Help
« Reply #11 on: July 21, 2008, 06: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.

Apocalypse

  • Autococker
  • Posts: 1463
Re: More VB6 Help
« Reply #12 on: July 22, 2008, 08:35:25 AM »
Thanks greatly appreciated I have programmed a very small amount in C++ but I never made anything very big with it.