Hi
I want to stop a code firing if a certain condition is not met. I only want to allow numeric entries in the textbox to allow the code to run. I tried with the first line of code to stop it, but obviously am failing in my attempt. - If 26 = AlphaNumeric Then Stop
-
Dim ba26 As String
-
Dim fileName As String
-
fileName = App.Path & "\" & "\data\ba26.txt"
-
ba26 = FreeFile
-
Open fileName For Output As #ba26
-
Print #ba26, Text26.Text
-
Close #ba26
Thanks Werner
6 2907
Hi
I want to stop a code firing if a certain condition is not met. I only want to allow numeric entries in the textbox to allow the code to run. I tried with the first line of code to stop it, but obviously am failing in my attempt.
If 26 = AlphaNumeric Then Stop
Dim ba26 As String
Dim fileName As String
fileName = App.Path & "\" & "\data\ba26.txt"
ba26 = FreeFile
Open fileName For Output As #ba26
Print #ba26, Text26.Text
Close #ba26
Thanks Werner
Hi there -
You can use EXIT SUB or EXIT FUNCTION in place of STOP. If these lines of code above is contained in a subfunction, use EXIT SUB. If its in the Function, use the latter.
And you may rewrite the code
If 26 = AlphaNumeric Then Stop
into
If NOT isnumeric(strParameter) then Exit SUB/FUNCTION
Note: I've replaced 26 with a variable strParameter.
What is 26 by the way? A literal? It's not good practice to have literal in there. You may use parameter or a variable to hold it.
Hi there -
You can use EXIT SUB or EXIT FUNCTION in place of STOP. If these lines of code above is contained in a subfunction, use EXIT SUB. If its in the Function, use the latter.
And you may rewrite the code
If 26 = AlphaNumeric Then Stop
into
If NOT isnumeric(strParameter) then Exit SUB/FUNCTION
Note: I've replaced 26 with a variable strParameter.
What is 26 by the way? A literal? It's not good practice to have literal in there. You may use parameter or a variable to hold it.
Hi, thanks got it sorted, 26 was meant to read ba26 - sorry! I have actually used something different which has worked perfectly - do you see a future problem with this?
Valid = Abs(CInt(Text26.Text))
If Valid < 0 Then Stop
Thanks
Werner
... do you see a future problem with this?
Valid = Abs(CInt(Text26.Text))
If Valid < 0 Then Stop
I do. Nothing serious, just that it can't possibly work. :)
To the best of my knowledge, the value returned by the Abs() function cannot be less than zero. So this test will always fail, no matter what the value of Text26.Text.
I suppose it's up to you, whether you consider that a problem or not.
I do. Nothing serious, just that it can't possibly work. :)
To the best of my knowledge, the value returned by the Abs() function cannot be less than zero. So this test will always fail, no matter what the value of Text26.Text.
I suppose it's up to you, whether you consider that a problem or not.
Well, that is why you re the expert and i the idiot trying to operate VB6 :->>
Anyway, I suppose it is not the correct way in working, but it solves the problem i had in that if you had entered a alpha into the textbox, you would get a error, the program would shut down and then when you try to launch again it said type mismatch. This way it gives the error, shuts down, but on relaunch it is fine and has not saved to error to file. The field is not that serious, but would not want it from stopping the software to relaunch.
Thanks again
I do. Nothing serious, just that it can't possibly work. :)
To the best of my knowledge, the value returned by the Abs() function cannot be less than zero. So this test will always fail, no matter what the value of Text26.Text.
I suppose it's up to you, whether you consider that a problem or not.
Additional Information and maybe, more appropriate for Abs() function is, as its name implies... it is the absolute value of the parameter. In your case, the content of the Text26 textbox object.
In short, integer value will always be POSITIVE...
like: Abs(25) = 25, Abs(-25) = 25, Abs(+25) = 25...
Additional Information and maybe, more appropriate for Abs() function is, as its name implies... it is the absolute value of the parameter. In your case, the content of the Text26 textbox object.
In short, integer value will always be POSITIVE...
like: Abs(25) = 25, Abs(-25) = 25, Abs(+25) = 25...
Thanks for the info.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: JT |
last post by:
is it possible to somehow "jump out of" an ASP page that is executed from
another page via the Server.Execute method?
on the page being executed i have several instances where i need to stop the...
|
by: Jon Brunson |
last post by:
I've got a class in a plugin (loaded at run-time) with a Property of
type Control. This Control is added to a Panel at run-time when a Form
loads.
Later on, when the "serial port data received"...
|
by: David |
last post by:
Hi everyone,
I am trying to stop an image preload sequence by the click of a mouse but
have been unsuccessful trying several methods. Imagine this simple script
below that loads 50 images to...
|
by: ohnoonho |
last post by:
Hello,
I posted this in the C# group but thought maybe the better place would
be here since it is happening with website projects so please forgive
any cross posting.
In my website projects I...
|
by: Mark Huebner |
last post by:
I have an aspx web page with the following C# code in the page load event.
Can somebody tell me if the Response.Redirect() will cause my tLoadDNN
thread to stop executing before it is finished? ...
|
by: Torben Laursen |
last post by:
Hi
My interface calls a C++ dll that runs a slow calculations.
So I call the dll inside a BackgroundWorker thread, and that all works fine.
But how can I stop the thread if the user wants to?...
|
by: diego |
last post by:
Greetings everyone!
Is there a way to stop query analyzer from processing remaining query
statements? Let's say i have the following query in query analyzer:
query statements
if condition...
|
by: Richard Maher |
last post by:
Hi,
I am in a mouseup event for button A and I'd like to disable=false button B
before starting some work. Is there anyway that an event for button B can
then fire before my event processing for...
|
by: mattcfisher |
last post by:
Hi,
I have two windows services running together. One is the main
program, and one is an "updater" wrapper for the main. The updater
service starts and stops the main one (as in you should never...
|
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...
|
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...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
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...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
|
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...
| |