| | |
Help With syntax
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
i have a problem making the code for this logic
i have 5textbox ,1 label and a command button on a form and
need to do this:
and so on.. until the 5th
'''''''''''''''''''''''''''''''''''''''''''''''''''
i tried making code like
if txt1 > txt2 then
label1.caption = txt1
end if
if txt1 > txt3 then
label1.caption = txt1
end if
and so on...
but having a problem when it come to comparing the
"2nd to the 1st"
"3rd to the 1st"
and so on .....
it still have a problem on selecting the highest value on the 5 textboxes
pls help me............. getting dizzy thinking of the solution
i have 5textbox ,1 label and a command button on a form and
need to do this:
•
•
•
•
if the value of the 1st textbox is greater than the 2nd,3rd,4th,5th
then label1.caption = to the value of the 1st text box
•
•
•
•
if the value of the 2nd textbox is greater than the 1st,3rd,4th,5th
then label1.caption = to the value of the 1st text box
'''''''''''''''''''''''''''''''''''''''''''''''''''
i tried making code like
if txt1 > txt2 then
label1.caption = txt1
end if
if txt1 > txt3 then
label1.caption = txt1
end if
and so on...
but having a problem when it come to comparing the
"2nd to the 1st"
"3rd to the 1st"
and so on .....
it still have a problem on selecting the highest value on the 5 textboxes
pls help me............. getting dizzy thinking of the solution
Last edited by hawisme000; Feb 19th, 2008 at 10:53 am.
•
•
Join Date: May 2005
Posts: 514
Reputation:
Solved Threads: 19
Make sure that you define these variables integer based.
it might be doing a text comparison because of data type.
Store the variables into a temp var that is defined as integer and then run them through your if statements.
it might be doing a text comparison because of data type.
Store the variables into a temp var that is defined as integer and then run them through your if statements.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
if txt1 > txt2 or txt1 > txt3 or txt1 > txt4 or txt1 > txt5 then label1.caption = txt1
why use or??
if the value 3 2 4 5 6 then the result is 3 cause the first state is pass (3 > 2).
when use or operand, if one state was passed then another state not checked by prog again.
use and operand.
if the value 3 2 4 5 6 then the result is 3 cause the first state is pass (3 > 2).
when use or operand, if one state was passed then another state not checked by prog again.
use and operand.
vb Syntax (Toggle Plain Text)
If Val(Text1.Text) > Val(Text2.Text) And Val(Text1.Text) > Val(Text3.Text) And Val(Text1.Text) > Val(Text4.Text) And Val(Text1.Text) > Val(Text5.Text) Then Label1.Caption = Text1.Text End If
Last edited by Jx_Man; Feb 19th, 2008 at 12:03 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
why you are using 5 separate boxes? to solve this problem more efficiently try control arrays. this will be more easier for you. check out this sample code, it is implemented on control arrays. one advantage of this code is you do not need to encounter each & every textboxes to find out the maximum value among all values. you do not need to write those long if conditions also. this code is dynamic. it is capable to find out the max. value without bothering how many textboxes u used in your form. just put a single textbox and make no. of copies of it that you want. this will create the control arrays of the textbox. now put a label and fire this code. you will get your answer.
ok by implementing this logic i've not meant that others methods are not workable. no i'm not saying that at all. but this logic is more practical.
try this and get me your feedback.
ok......
good luck
regards
Shouvik
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim ctlControl As Object Dim x() As Integer, c As Integer, i As Integer, max As Integer c = 0 On Error Resume Next For Each ctlControl In Me.Controls If TypeOf ctlControl Is TextBox Then c = c + 1 DoEvents End If Next ctlControl ReDim Preserve x(c) max = Text1.Item(0) For i = LBound(x) To UBound(x) - 1 Step 1 If max < Val(Text1.Item(i)) Then max = Val(Text1.Item(i)) Else max = max End If Next i Label1.Caption = max
ok by implementing this logic i've not meant that others methods are not workable. no i'm not saying that at all. but this logic is more practical.
try this and get me your feedback.
ok......
good luck
regards
Shouvik
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
i post it cause previous post use or operand.
but you have a great code. nice one
but you have a great code. nice one
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
•
•
ok by implementing this logic i've not meant that others methods are not workable. no i'm not saying that at all.
have a nice day
regards
Shouvik
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
SORRY FOR THE VERY LATE REPLY EVERY ONE, JUst got home from school,
sir shouvi
im having a proj about my subject --> OS (Operating System)
and he want me to make a program about "Priority First"
like .. this (just sharing the story why i came up with this prob
)
------------CPUTIME-------------------PRIORITY TIME
P1-------------#----------------------------------#
P2-------------#----------------------------------#
P3-------------#----------------------------------#
P4-------------#----------------------------------#
P5-------------#----------------------------------#
where # is the input number
--------------------------------------------------------------------
as you can see from above there is 5 input for Priority time , 1 for each P#
thats y i came up with the idea of using 5txtbox(but i dndt think of using array ,thx 4 dat)
im currently making it again, wit the use of the syntax u gave (ty all!)
''
il reply again of what came up
TY OL!!!
sir shouvi
im having a proj about my subject --> OS (Operating System)
and he want me to make a program about "Priority First"
like .. this (just sharing the story why i came up with this prob
)------------CPUTIME-------------------PRIORITY TIME
P1-------------#----------------------------------#
P2-------------#----------------------------------#
P3-------------#----------------------------------#
P4-------------#----------------------------------#
P5-------------#----------------------------------#
where # is the input number
--------------------------------------------------------------------
as you can see from above there is 5 input for Priority time , 1 for each P#
thats y i came up with the idea of using 5txtbox(but i dndt think of using array ,thx 4 dat)
im currently making it again, wit the use of the syntax u gave (ty all!)
''
il reply again of what came up
TY OL!!!
Last edited by hawisme000; Feb 20th, 2008 at 10:06 am.
sir shouvi!!! ur code is Great!!!
i does solve my prob, ty soo much,
but before i end this post , on your code,
there are part of it i cant understan (the code's meaning and use)
it my 1st time encountering this part of the code
-Me.Controls (does this point for the objects in the form to?? like ,Dim ctlControl As Object)
-DoEvents (umm.. where is the event? umm..where it start?)
-ReDim Preserve x(c) (does it preserve all values put on dim C?? cnt understand d logic)
-For i = LBound(x) To UBound(x) - 1 Step 1
(also how to read this in logic)
pls?? wanna learn this part really,
jx_man ty for the help and ideas too,,
i does solve my prob, ty soo much,
but before i end this post , on your code,
there are part of it i cant understan (the code's meaning and use)
it my 1st time encountering this part of the code
-Me.Controls (does this point for the objects in the form to?? like ,Dim ctlControl As Object)
-DoEvents (umm.. where is the event? umm..where it start?)
-ReDim Preserve x(c) (does it preserve all values put on dim C?? cnt understand d logic)
-For i = LBound(x) To UBound(x) - 1 Step 1
(also how to read this in logic)
pls?? wanna learn this part really,
jx_man ty for the help and ideas too,,
•
•
•
•
sir shouvi!!! ur code is Great!!!
i does solve my prob, ty soo much,
but before i end this post , on your code,
there are part of it i cant understan (the code's meaning and use)
it my 1st time encountering this part of the code![]()
-Me.Controls (does this point for the objects in the form to?? like ,Dim ctlControl As Object)
-DoEvents (umm.. where is the event? umm..where it start?)
-ReDim Preserve x(c) (does it preserve all values put on dim C?? cnt understand d logic)
-For i = LBound(x) To UBound(x) - 1 Step 1
(also how to read this in logic)
pls?? wanna learn this part really,![]()
jx_man ty for the help and ideas too,,
i am solving one by one. this is going to be a long post. plz hv patience when u read it.
your first question :- Me.Controls (does this point for the objects in the form to?? like ,Dim ctlControl As Object)
Answer : quiet so but not the same as ctlcontrol. here ctlcontrol is just an instance of the object type. as the code is dynamic (capable to encounter every textboxes without bothering how many r there) how could it do that?
notice this line : for each ctlcontrol in me.controls
this line is telling the compiler to iterate through each objects represented as controls in the current form and if the currently scanned object is a textbox then just increament the value of c by 1. here c is declared to store the total no. of textboxes present in the current form. so in this way you will get how many tb you have in ur form and it doesn't require you to maintain code for each textboxes.
your second question : - DoEvents
Answer : this is a system defined procedure. this is not indicating to any physical events that may exists on any of ur forms. DoEvents is a predefined sub-routine in vb6 which yield execution of an ongoing process of the compiler so the operating system can perform other operations that are waiting in the process queue.
your third question : ReDim Preserve x(c) (does it preserve all values put on dim C??
Answer : see i've declared an array there ----->dim x() as integer, here x is an integer array but have you noticed the "()"? look there is no dimension size mentioned. as we all know an array must be initialized when the same is declared. now in the code u r trying to iterate through each text box and counting how many of them r there. but before running the for each..next statement how could the program will know how many text boxes are there? it can't be and x() is declared to store the values of each text box one by one. so, in such case when we do not know the dimension size from advance we can declare an array with null no of elements means it can hold n number of values. now after running the for each..next statement when we found total no. of text boxes then what we will do, we just re-initialize the array with the appropriate dimension size we just got in order to make sure that our program is not accessing un-neccessery memory. in vb you use Redim to re-declare a variable and that's what exactly i'm doing here Redim Preserve x(c)
now this line is just re-declaring the array x with a proper dimension size computed dynamically which is stored in the variable c. for example, u have a 5 text boxes. so c will contain 5 and when this line is fired x will be re-declared & re-initialized with dimension 5 and it will look like as x(5). the preserve command is used to store the new dimension size.
your fourth question : -For i = LBound(x) To UBound(x) - 1 Step 1
Answer : See the logic involved in this code is very simple. after counting each instance of the text boxes i'm running a for loop to store value of each tb into current element of the integer array x. that is implemented by using Text1.item(index), for example x(0)=text1.item(0) , it will store value of the first tb in sequence into the first element of array x and so on. now after taking values we need to take a value and compare it with rest of each one to find the max. value. now to iterate through an array you must start from element 0 and the process must stop when u reach the last element which is total dimnesion size-1. the ubound() returns the highest element no./index/subscript of an array. in this case it is 5 but we need to iterate from 0 to 4. otherwise system will fetch "subscript out of range" error. so how can we find the last/final element to scan? for this this is used ubound(x)-1 , which returns 4 i.e. total dm size (5) - 1 =4. similarly lbound returns the first index of the array which is always be 0. so u can mention 0 in case of lbound(x) also.
hope these explanations are enough to clear ur doudts.
if u want more then just do some googling.......
ok......
bye
regards
Shouvik
Last edited by choudhuryshouvi; Feb 20th, 2008 at 2:33 pm.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
![]() |
Similar Threads
- MySQL syntax error check for the right syntax to use near 'A (A) )' at line 1 (PHP)
- Error "Syntax" (Windows 95 / 98 / Me)
- DECLARATION SYNTAX ERROR (for bc 31 user) (C++)
- MySQL newbie need help with create table definitons syntax (MySQL)
- Parse error, syntax error, Forbids declaration (C++)
- Syntax for deleting specified file ( in C++) (C++)
- C++ Syntax (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Focus Rectangle with XP Manifest
- Next Thread: accademic issues in visual basic
Views: 1480 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






