Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 26th, 2003, 06:35 PM
Mig Officer Mig Officer is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 2 Mig Officer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Lost value in If Statements

My third variable will not gain the value of the equation, when opt 2 or 3 is selected. Can someone help please...


It's just an example of what I want to achieve.


Code ----------------------------------
Code:

Private Sub Command1_Click()
Dim g1 As Variant
Dim g2 As Variant
Dim g3 As Variant

g2 = val1.Text
g3 = val2.Text


If Opt1.Value = 1 Then
    If Op4.Value = 1 Then
        g1 = g2 / g3
    ElseIf Op5.Value = 1 Then
        g1 = g2 + g3
    ElseIf Op6.Value = 1 Then
        g1 = g2 - g3
ElseIf Opt2.Value = 1 Then
    If Op4.Value = 1 Then
        g1 = g2 / g3
    ElseIf Op5.Value = 1 Then
        g1 = g2 + g3
    ElseIf Op6.Value = 1 Then
        g1 = g2 - g3
ElseIf Opt3.Value = 1 Then
    If Op4.Value = 1 Then
        g1 = g2 / g3
    ElseIf Op5.Value = 1 Then
        g1 = g2 + g3
    ElseIf Op6.Value = 1 Then
        g1 = g2 - g3
Else
 MsgBox "Done"
 End If
 End If
 End If
End If
Res.Text = g1
End Sub
*edit* added code tags

Last edited by Onslaught : September 27th, 2003 at 11:21 AM.

Reply With Quote
  #2  
Old September 27th, 2003, 12:15 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
u can post your full code to us for help u??

Reply With Quote
  #3  
Old September 27th, 2003, 01:00 AM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,790 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 14 h 29 m 54 sec
Reputation Power: 746
Mig, try using the [ code ] .. [ /code ] or [ php ] .. [ /php ] forum codes (without the spaces) to preserve spacing and indenting in your code. It's hard to follow when there are no indents.

Reply With Quote
  #4  
Old September 27th, 2003, 11:34 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 20 m 5 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
I added code tags around your code so that we can see the indentation, but seeing this makes me realize that your if statements are slightly off.
This is what vb sees:
Code:
Private Sub Command1_Click()
	Dim g1 As Variant
	Dim g2 As Variant
	Dim g3 As Variant

	g2 = val1.Text
	g3 = val2.Text


	If Opt1.Value = 1 Then
		If Op4.Value = 1 Then
			g1 = g2 / g3
		ElseIf Op5.Value = 1 Then
			g1 = g2 + g3
		ElseIf Op6.Value = 1 Then
			g1 = g2 - g3
		ElseIf Opt2.Value = 1 Then
			If Op4.Value = 1 Then
				g1 = g2 / g3
			ElseIf Op5.Value = 1 Then
				g1 = g2 + g3
			ElseIf Op6.Value = 1 Then
				g1 = g2 - g3
			ElseIf Opt3.Value = 1 Then
				If Op4.Value = 1 Then
					g1 = g2 / g3
				ElseIf Op5.Value = 1 Then
					g1 = g2 + g3
				ElseIf Op6.Value = 1 Then
					g1 = g2 - g3
				Else
					MsgBox "Done"
				End If
			End If
		End If
	End If
	Res.Text = g1
End Sub

Reply With Quote
  #5  
Old September 27th, 2003, 05:07 PM
Mig Officer Mig Officer is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 2 Mig Officer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Wink THanks for your help

If anyone can give me an answer I will add you as one of the coders to the program. It's for a goverment department in Australia.

Reply With Quote
  #6  
Old September 27th, 2003, 11:34 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Hi Mig Officer! I try your code,but i find if opt1.value<>true,the follow statements are not runned!!U can tell us what your code meaning??..And then Thx Onslaught's work!..

Reply With Quote
  #7  
Old September 27th, 2003, 11:54 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 20 m 5 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Try something along these lines:
Code:
Private Sub Command1_Click()
	Dim g1 As Variant
	Dim g2 As Variant
	Dim g3 As Variant

	g2 = val1.Text
	g3 = val2.Text


	If Opt1.Value = 1 Then
		If Op4.Value = 1 Then
			g1 = g2 / g3
		ElseIf Op5.Value = 1 Then
			g1 = g2 + g3
		ElseIf Op6.Value = 1 Then
			g1 = g2 - g3
		End If
	Else If Opt2.Value = 1 Then
		If Op4.Value = 1 Then
			g1 = g2 / g3
		Else If Op5.Value = 1 Then
			g1 = g2 + g3
		Else If Op6.Value = 1 Then
			g1 = g2 - g3
		End If
	Else If Opt3.Value = 1 Then
		If Op4.Value = 1 Then
			g1 = g2 / g3
		Else If Op5.Value = 1 Then
			g1 = g2 + g3
		Else If Op6.Value = 1 Then
			g1 = g2 - g3
		End If
	Else
		MsgBox "Done"
	End If
	Res.Text = g1
End Sub
If you look closely where the End If statements are located so that it closes each If block, this will probably result in what you are wanting.

Reply With Quote
  #8  
Old September 28th, 2003, 01:45 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Yeah!Onslaught,U are cleverman!I'm cleverpig?!!haha!!THX..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Lost value in If Statements


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway