473,325 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Using If statement between 2 text boxes in VB6

104 100+
Please could anyone tell me what is wrong with this code.

Do I need anything else other than this for it to work, or is my code missing further info requirements. Presently getting no result in Ret1.text5

If Ret1.text4 = 100 Then Ret1.Text5 = Wrong

Thank you
Werner
Jul 26 '07 #1
27 4785
Hi, if you are trying to check that the text box contains the string 100, u need the quotation marks...
i.e. if textbox.Text = "100".

If you are trying to check if it is a number you will need to parse the string to a number. (in this case integer)

i.e. Integer.Parse(TextBox.Text)

note.. this is for VB.net

Also you would need stirng notation around te text you are trying to enter
Jul 26 '07 #2
hariharanmca
1,977 1GB
Please could anyone tell me what is wrong with this code.

Do I need anything else other than this for it to work, or is my code missing further info requirements. Presently getting no result in Ret1.text5

If Ret1.text4 = 100 Then Ret1.Text5 = Wrong

Thank you
Werner

You never mentioned, what is your front-end and what it means for Ret1?

Expand|Select|Wrap|Line Numbers
  1. If Val(txtName1.Text) = 100 Then txtName2.Text = valSomeValue
This will be correct.
Jul 26 '07 #3
Wernerh
104 100+
You never mentioned, what is your front-end and what it means for Ret1?

Expand|Select|Wrap|Line Numbers
  1. If Val(txtName1.Text) = 100 Then txtName2.Text = valSomeValue
This will be correct.
Hi, thanks it was just the "" that was omitted. It works perfectly now.

Thanks for the help.

Werner
Jul 26 '07 #4
Wernerh
104 100+
One more question if you could maybe have a look for me. I have a excel book that is opened by a command button running this script. It gives me object error. All I want it to do it open the book (which it does no problem) and then run the if statement. Gives me the error when it gets to that part. This is VB6

Private Sub Command3_Click()

Set xlBook = GetObject("c:\miprice software\data\retail.xls")
' Display Microsoft Excel and the Worksheet
' window.
xlBook.Application.Visible = True
xlBook.Windows(1).Visible = True


If textbox4.Text < " 100" Then

'Copy text fields Part 1
Retail.Range("g5") = textbox4.Text

Else

'Copy text fields Part 2
Retail.Range("g5") = textbox5.Text

End If

End Sub

Thanks once again.
Jul 26 '07 #5
hariharanmca
1,977 1GB
One more question if you could maybe have a look for me. I have a excel book that is opened by a command button running this script. It gives me object error. All I want it to do it open the book (which it does no problem) and then run the if statement. Gives me the error when it gets to that part. This is VB6

Private Sub Command3_Click()

Set xlBook = GetObject("c:\miprice software\data\retail.xls")
' Display Microsoft Excel and the Worksheet
' window.
xlBook.Application.Visible = True
xlBook.Windows(1).Visible = True


If textbox4.Text < " 100" Then

'Copy text fields Part 1
Retail.Range("g5") = textbox4.Text

Else

'Copy text fields Part 2
Retail.Range("g5") = textbox5.Text

End If

End Sub

Thanks once again.

If textbox4.Text < " 100" Then

are you sure that should be " <Space>100".
okay, If you go for that
then use

If Trim(textbox4.Text) = "100" Then

what is the error that you are getting?
Jul 26 '07 #6
Hey, I'm not too familiar with VB6, but i think that the statement
Expand|Select|Wrap|Line Numbers
  1.  If textbox4.Text < " 100" Then 
is the problem...

You are asking if a string is less than another string... which if you think about it, doesnt really make sense.

If you are trying to find if the number entered into the textbox4 is less than 400, then you need to parse the text as an integer or a double... in vb.net this would be

Expand|Select|Wrap|Line Numbers
  1.  If Integer.Parse(textbox4.text) < 100 Then 
That will check if the number entered into the text box is less than 100... is this what you wanted?
Jul 26 '07 #7
Wernerh
104 100+
Hey, I'm not too familiar with VB6, but i think that the statement
Expand|Select|Wrap|Line Numbers
  1.  If textbox4.Text < " 100" Then 
is the problem...

You are asking if a string is less than another string... which if you think about it, doesnt really make sense.

If you are trying to find if the number entered into the textbox4 is less than 400, then you need to parse the text as an integer or a double... in vb.net this would be

Expand|Select|Wrap|Line Numbers
  1.  If Integer.Parse(textbox4.text) < 100 Then 
That will check if the number entered into the text box is less than 100... is this what you wanted?
Yes, I want it to read the value ot that textbox and if it is < than 100 to follow the rest of the statement. The bottom line is i am trying to get that result posted in a excel sheet. The error I am getting is "run time error" object required.
Jul 26 '07 #8
Wernerh
104 100+
Yes, I want it to read the value ot that textbox and if it is < than 100 to follow the rest of the statement. The bottom line is i am trying to get that result posted in a excel sheet. The error I am getting is "run time error" object required.
I actually don't need to use the if statement as all i am trying to do is to get the textbox4 posted in excel. I can then in excel write a if statement which is easy.
Jul 26 '07 #9
hariharanmca
1,977 1GB
I actually don't need to use the if statement as all i am trying to do is to get the textbox4 posted in excel. I can then in excel write a if statement which is easy.

It is difficult to get only in some piece of code. And you have to explain more.
Jul 26 '07 #10
Wernerh
104 100+
It is difficult to get only in some piece of code. And you have to explain more.
Ok, will try.


The function requirement is simple, but the actual coding is what is the problem. The first part opens a specific Xls workbook - that runs no problem. The second part is trying to enter a figure form a textbox into the workbook. As I said I don't need to use specifically the if code if there is another wa, this just seemd the easiest way. Hope that makes more sense. Sorry for the hassle.

Here is the whole code:

Private Sub Command3_Click()

Set xlBook = GetObject("c:\miprice software\data\retail.xls")
' Display Microsoft Excel and the Worksheet
' window.
xlBook.Application.Visible = True
xlBook.Windows(1).Visible = True


If textbox4.Text < " 100" Then

'Copy text fields Part 1
Retail.Range("g5") = textbox4.Text

Else

'Copy text fields Part 2
Retail.Range("g5") = textbox4.Text

End If

End Sub
Jul 26 '07 #11
Wernerh
104 100+
Ok, will try.


The function requirement is simple, but the actual coding is what is the problem. The first part opens a specific Xls workbook - that runs no problem. The second part is trying to enter a figure form a textbox into the workbook. As I said I don't need to use specifically the if code if there is another wa, this just seemd the easiest way. Hope that makes more sense. Sorry for the hassle.

Here is the whole code:

Private Sub Command3_Click()

Set xlBook = GetObject("c:\miprice software\data\retail.xls")
' Display Microsoft Excel and the Worksheet
' window.
xlBook.Application.Visible = True
xlBook.Windows(1).Visible = True


If textbox4.Text < " 100" Then

'Copy text fields Part 1
Retail.Range("g5") = textbox4.Text

Else

'Copy text fields Part 2
Retail.Range("g5") = textbox4.Text

End If

End Sub
When I debug it stops at
If textbox4.Text < " 100" Then

and then says : Object required.
Jul 26 '07 #12
Wernerh
104 100+
When I debug it stops at
If textbox4.Text < " 100" Then

and then says : Object required.
do you know of a simple code that will take the value of textbox4 and post it into excel cell g5?
Jul 26 '07 #13
hariharanmca
1,977 1GB
Ok, will try.


If textbox4.Text < " 100" Then

End If

End Sub

still cannot get this
If textbox4.Text < " 100" Then

why not this
If val(textbox4.Text) < 100 Then
Jul 26 '07 #14
Wernerh
104 100+
still cannot get this
If textbox4.Text < " 100" Then

why not this
If val(textbox4.Text) < 100 Then
I have used the code like you have suggested, but still same object required error. :-<<
Jul 26 '07 #15
hariharanmca
1,977 1GB
I have used the code like you have suggested, but still same object required error. :-<<

can you say which line is that object error?
Jul 26 '07 #16
Wernerh
104 100+
can you say which line is that object error?
Highlights the first line : If Val(textbox4.Text) < 100 Then
Jul 26 '07 #17
hariharanmca
1,977 1GB
Highlights the first line : If Val(textbox4.Text) < 100 Then
just check the textbox name is 'textbox4'
Jul 26 '07 #18
Wernerh
104 100+
just check the textbox name is 'textbox4'

Damn that was wrong it is actually text4 not textbox4, but still same error! I am not sure if I should preceed that part of the code with maybe something like :

Dim text4 as Integer ???? - tried it,but then said invalid qualifier.
Jul 26 '07 #19
hariharanmca
1,977 1GB
Damn that was wrong it is actually text4 not textbox4, but still same error! I am not sure if I should preceed that part of the code with maybe something like :

Dim text4 as Integer ???? - tried it,but then said invalid qualifier.
Already text4 is an textbox control then how can you declare it again for integer?
Jul 26 '07 #20
Wernerh
104 100+
Already text4 is an textbox control then how can you declare it again for integer?

Pure shot in the dark! I am as you can see a TOTAL newbie at this, so just starting to learn all the bits and pieces.
Jul 26 '07 #21
Killer42
8,435 Expert 8TB
Pure shot in the dark! I am as you can see a TOTAL newbie at this, so just starting to learn all the bits and pieces.
I think all the textbox business is probably somewhat incidental to the main issue, which is that (unless things work a lot differently to VB6) there is no object in your application called Retail. Most likely, you need to change Retail.Range("g5") to a proper reference to xlBook or one of the WorkSheet objects contained within it.
Jul 26 '07 #22
rcollins
234 100+
I am having a similar problem in my code. Should be simple, what am I missing?
Expand|Select|Wrap|Line Numbers
  1. If Val(StandardizedAllocation.Text) = "HOUSE MEETINGS: " Then StandardizedAllocationSumm.Text = "Consult with direct care staff ongoing medical concerns and plan of care."
  2. End If
  3.  
Oct 9 '07 #23
Killer42
8,435 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. If Val(StandardizedAllocation.Text) = "HOUSE MEETINGS: " Then StandardizedAllocationSumm.Text = "Consult with direct care staff ongoing medical concerns and plan of care."
  2. End If
  3.  
Well, I don't know exacly what problem you are having. But I can see two fairly obvious problems with this code.
  • The purpose of the Val() function is to take a string, convert it, and return a number. So it doesn't make any sense to compare the result to "HOUSE MEETINGS: ".
  • Since you've coded the IF on a single line, it doesn't require (or perhaps it would be more precise to say it doesn't allow) an End If. To demonstrate the difference, these two pieces of code do precisely the same thing...
    Expand|Select|Wrap|Line Numbers
    1. ' Single-line...
    2. If A = 1 Then B = 3
    3.  
    4. ' Multi-line...
    5. If A = 1 Then
    6.   B = 3
    7. End If
Oct 9 '07 #24
rcollins
234 100+
So, per you example, this is what I have now
Expand|Select|Wrap|Line Numbers
  1. If StandardizedAllocation.Text = HOUSE MEETINGS: Then StandardizedAllocationSumm.Text = Consult with direct care staff ongoing medical concerns and plan of care.
  2.  
I still don't get anything returned in the second text box.
Oct 10 '07 #25
rcollins
234 100+
Here is the error I am getting now: "You can't reference a property or method for a control unless the control has the focus."
Here is my exact code for picking from two choises. I only get this error on the first choice, but don't get anything in the text box with the second one.

Expand|Select|Wrap|Line Numbers
  1. Private Sub StandardizedAllocation_AfterUpdate()
  2. If StandardizedAllocation.Text = "HOUSE MEETINGS:" Then StandardizedAllocationSumm.Text = "Consult with direct care staff ongoing medical concerns and plan of care."
  3. If StandardizedAllocation.Text = "MD Appt.Prep:" Then StandardizedAllocationSumm.Text = "Case file reviewed for pending medical appointment.  Plan of care reviewed and updated."
  4.  
  5. End Sub
  6.  
Oct 10 '07 #26
rcollins
234 100+
Got it working, another member helped me. Thanks
Oct 10 '07 #27
Killer42
8,435 Expert 8TB
"You can't reference a property or method for a control unless the control has the focus."
You said you were using VB6. VB6 does not report this error. Unless I'm gravely mistaken, this is an MS Access message.

Anyway, glad to hear you got it working.
Oct 10 '07 #28

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dmiller23462 | last post by:
Hey guys.... I put an error-handling in my page and have it posted at the complete end of the code, see below(when people were putting in 's I was getting the delimiter errors). Great, I...
8
by: abbylee26 | last post by:
User enters account number if another account number is needed User clicks add account which creates another row When validating when they hit submit I want to check to make sure they tell us...
3
by: amywolfie | last post by:
Hi All: I would like to run a report based on criteria from 3 unbound combo boxes located on a parameter form (combo boxes are: cboCuisine, cboLocation, and cboRestaurant) The present code...
11
by: DP | last post by:
hi, i have a films table and form. i have a txt field in teh form called txtSearch , and i;ve created a query with all the film table fields in it. how can i get the query to load up, wth the...
10
by: Paul | last post by:
Hi I am using the HtmlInputFile control to upload a file from a client to a server. I have a browse to find the file on the server but need to create the path dynamically as to were it will go...
7
by: ljungers | last post by:
Have Form-1 with 3 text boxes and 1 command button. With any of the 3 boxes filled out and button is clicked, a Macro is performed that Opens a Query that has a WHERE clause that uses the 3 test...
10
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created...
8
by: Gari | last post by:
Hello, I am trying to build a filter query with some AND and OR. I have three text boxes and 5 check boxes. The checkboxes are linked via code to other textboxes for the purpose of the query. ...
2
by: chaosdl | last post by:
Hello, I am currently using Visual Basic 2005 express edition with a MS Access database. I have made a "Contacts" Form, where the user will be able to enter a members surname and press an OK...
10
by: metalheadstorm | last post by:
OK i have two listboxes that are populated by data from a Access Db, its populated by a if statement sayin if the data is the same as todays date put it in list box1 and if its tomorrows date but...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.