Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 17th, 2009, 11:56 AM   #1
Rem1978
Programmer
 
Join Date: May 2009
Posts: 39
Rep Power: 0 Rem1978 is on a distinguished road
Expression Expected error Help!!

I'm trying to learn VB and have been following examples in my text.

I have 4 radiobuttons on my form and a button to click to enter data.

It's a simple example in the book but I keep getting expression expected errors when I type in the code.

I have 4 variables dimensioned, FreshmanCountInteger, SophomoreCountInteger, JuniorCountInteger and SeniorCountInteger

Code looks like:

If FreshmanRadioButton.Checked Then
FreshmanCountInteger += 1
ElseIf
SophomoreRadioButton.Checked Then
SophomoreCountInteger +=1
ElseIf
JuniorRaioButton.Checked Then
JuniorCountInteger += 1
ElseIf
SeniorRadioButton.Checked Then
SeniorCountIntger += 1
____________________________________
The If part of the first ElseIf has the squiggly line and the error "Expression expected" There isn't an error in the first If statement but the trouble starts
with that first ElseIf and proceeds with an error in SophomoreRadioButton.Checked Then which states Property access must assign to the property or use it's value.

This is very basic but I'm just trying to understand how to use these type of statements to learn, could someone please let me know how to correct this.
Rem1978 is offline   Reply With Quote
Old May 17th, 2009, 1:16 PM   #2
Alias
Hobbyist Programmer
 
Join Date: Oct 2007
Location: Newcastle upon Tyne, UK
Posts: 113
Rep Power: 8 Alias is on a distinguished road
Send a message via MSN to Alias Send a message via Skype™ to Alias
Re: Expression Expected error Help!!

You should use [code] tags - see, now I'm not sure whether something went wrong when you pasted your code, did it auto format of did you write it exactly like that?

btw, you using VB.NET? If not then this is the wrong place.

Ok, I'm a bit rusty but here goes, if you wrote it like that then VB really won't agree with new-lines between statements as in your code, put the whole conditional on one line.

iirc you can also use an underscore to specify the statement continues on the next line.

Also you miss an EndIf.

Try:

If FreshmanRadioButton.Checked Then
    FreshmanCountInteger += 1
ElseIf SophomoreRadioButton.Checked Then
    SophomoreCountInteger +=1
ElseIf JuniorRaioButton.Checked Then
    JuniorCountInteger += 1
ElseIf SeniorRadioButton.Checked Then
    SeniorCountIntger += 1
EndIf

Or...

If FreshmanRadioButton.Checked Then
    FreshmanCountInteger += 1
ElseIf _
  SophomoreRadioButton.Checked Then
    SophomoreCountInteger +=1
ElseIf _
  JuniorRaioButton.Checked Then
    JuniorCountInteger += 1
ElseIf _
  SeniorRadioButton.Checked Then
    SeniorCountIntger += 1
EndIf
Alias is offline   Reply With Quote
Old May 17th, 2009, 8:20 PM   #3
Rem1978
Programmer
 
Join Date: May 2009
Posts: 39
Rep Power: 0 Rem1978 is on a distinguished road
Re: Expression Expected error Help!!

Thanks...I'm not sure what you mean by code tags. I typed the code without pasting. I did have the EndIf but forgot to include in my first post. I'm not sure if it's .Net but book says Visual Basic 2008. It does say in opening chapter that you need to install .NET Framework for programs in this text. I'm guessing this is the right versions? I'll paste exactly what I have from my form. Did you mean that it's not working because I'm missing the underscore at the end of the ElseIf's?

Thanks for your help. My test is on Thursday and I'm already stuck on something simple like this.

Private Sub EnterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnterButton.Click


Dim FreshmanCountInteger As Integer
Dim SophomoreCountInteger As Integer
Dim JuniorCountInteger As Integer
Dim SeniorCountInteger As Integer

If FreshmanRadioButton.Checked Then
FreshmanCountInteger += 1
ElseIf
SophomoreRadioButton.Checked Then
SophomoreCountInteger += 1
ElseIf
JuniorRadioButton.Checked Then
JuniorCountInteger += 1
ElseIf
SeniorCountInteger.Checked Then
SeniorCountInteger += 1

End If
Rem1978 is offline   Reply With Quote
Old May 17th, 2009, 8:33 PM   #4
Rem1978
Programmer
 
Join Date: May 2009
Posts: 39
Rep Power: 0 Rem1978 is on a distinguished road
Re: Expression Expected error Help!!

Alias, I put those underscores in like you said and that solved the problem.
The text book didn't show those underscores in the example I took those statements from. I don't recall my teacher showing that either. I've seen the underscore used with the (& Environment.NewLine _). I didn't understand that it had to be included to make the If statement work.

So I should have put the statements all on one line, like:
ElseIf SophomoreRadioButton.Checked Then SophomoreCountInteger += 1


Thanks for your help. I wouldn't have figured it out!
Rem1978 is offline   Reply With Quote
Old May 18th, 2009, 11:43 AM   #5
Alias
Hobbyist Programmer
 
Join Date: Oct 2007
Location: Newcastle upon Tyne, UK
Posts: 113
Rep Power: 8 Alias is on a distinguished road
Send a message via MSN to Alias Send a message via Skype™ to Alias
Re: Expression Expected error Help!!

Ok, yep your using VB.NET - you should probably do some reading on the relationship of the language and framework.

I'm not sure why the book didn't use underscores for contiuation, the should have considering text-wrapping. Also the underscore is not exclusive to conditional statements, you can use it to continue any expression on a new line; for instance you can use it when concactinating string, like you seen with & Environment.NewLine _.

Rather than putting your whole statement on one line, you can and should continue on a new line after the Then - no underscore is required for continuation here.

So, anything between the If, or ElseIf and Then is an expression that would require continuation with an underscore to be syntactically correct whereas anything between the Then and the next ElseIf are their own statements/expressions so no underscore required after the Then.

Hope this is clear enough, anyway you'll pick up when and where to use it now you know of it's existence.

Glad you got your stuff working, just ask if you need anything else and I'll try to help, though there are probably some guru's here that know more than I - just don't know where they're at right now.
Alias is offline   Reply With Quote
Old May 18th, 2009, 11:53 AM   #6
kong
Hacker in Training
 
kong's Avatar
 
Join Date: Jan 2009
Posts: 104
Rep Power: 6 kong is on a distinguished road
Re: Expression Expected error Help!!

That funny! I didn't have any problem with your code. You didn't happen to have more than one end if statement did you?
kong is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Program for determining a valid expression dreamangel89 C 13 Mar 30th, 2009 3:12 AM
Error : Expression Expected neil82 Visual Basic .NET 2 Feb 18th, 2009 8:43 PM
Regular Expression paulchwd Software Design and Algorithms 9 Dec 3rd, 2008 1:52 PM
BinaryTree , I need help on inserting expression to the Tree Master C# 3 Oct 14th, 2005 3:42 PM
Regular Expression HELP -- thanks paulchwd JavaScript and Client-Side Browser Scripting 3 Oct 11th, 2005 4:40 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:30 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC