Tracker
 ASP PHP JavaScripts MySQL MS Access MSSQL VISUAL BASIC Subjects/Titles Post Text/Content
HOME    TRACKER    Visual Basic

# Check If Number Is Odd Or Even

## I use this codeVB Code:Function IsOdd(number as integer) as boolean    Dim tNum as integer    tNum=right(number,1)    if tNum=0 or tNum=2 or tNum=4 or tNum=6 or tNum=8 or tNum=10 then        IsOdd=false    else        IsOdd=true    end ifend function But are there any better way to check if it's odd or even?, because I need to call it thousand times in each secondThanks

A Fast Way To Check If A Number Is A Square Number?
Hi, I'm dealing with pretty big numbers (storing them in Decimal format) and I would like to know what the best way to check if the number is square or not. I could create an array of booleans which stores if each number is square or not but this is impractical as I would have to have the array contain about 100 thousand million million elements.

I thought I could just take the square root of a number and see if the square root was an integer or not. However this does not work with numbers such as:

139411375073318926

Which when stored as a Decimal gets rounded up to the nearest integer and so it appears to be a square number when it's not.

Is there a quick guarenteed way to test if a number is square or not?

How To Check If A Number Is Xyz?
how to check if number is like xyz
i mean that if my number is:
122312321
it will give me a msgbox

i hope you understood me
tnx Zebro

Check For A Whole Number
How do you Check for a whole number in Visual Basic

Check If Value Is Number
Hi all, an easy one.

I have a combo box, and the contents are 1, 2 and 3. but they are easily changed.

Is there an api to check if it is a number. I want the user to be able to change to another value, as long as it is a number.

cheers
ILMV

Check For A Number
How can I make sure the user enters a number into a field and give them an error message for anything else.

Check If A Number Is Odd?
VB Code:
Private Sub Command1_Click()    Dim number As Long    number = CInt(Rnd * 9999)    Text1.Text = numberEnd Sub

how can i check that the 'number' is odd or even please?

How To Check If The Value Is Number Or Not
hello all

i attach my program and i dont know how and were to do the thing that check if what the user enter with number value or not
i need it to be with number value

someone told me that its isnumeric or something like that
how to do it

Check For Number
i know this has been asked before i looked at it but took no notice

so how to check if the last char of a string is a number

Check To See If A Cell Is A Number
Visual Basic 6.3
Excel 2003

Hello,

I'm trying to write a code that looks at a cell and checks whether or not it is equal to a couple of texts, lies in a certain numeric range or none of the above. It then needs to flash up a message box saying "Invalid cell value" or something if none of the above are satisfied.

Everything is going fine, except when I try to include the bit about the numeric range. I have a series of Else If statements for the texts, and then the following for the number bit:

ElseIf 0 <= w <= 1 Then

Selection.NumberFormat = "0%"
Selection.Font.Bold = "False"
Selection.Font.ColorIndex = 0

Else

[show the invalid cell entry message]

The trouble is that when I run this, it accepts everything (including text) as being 0 <= w <= 1. (btw w is the cell value). When I set up 'w' as a string, it gives me a mismatch error when the cell being checked contains text, and accepts any number as lying in the range!

Setting up an error handler would be a pain in the ar5e as I would have to set up a lot of them. Is there any way of checking whether or not the cell value is a number or text at the start? Also, does VB deal with % cell entries and does it understand:

If n < X < m Then...

?

Thanks for reading this and any help would be appreciated.

Henry

Check If A Number Has Decimals?
how can i check if a number has decimals?

i tried with mod but mod wouldn't give the rest if it's smaller than one...

thx

How Do I Check If A Text Box Is A Number
i have a text box that i want to make a double vareable
how can i cheak that the value in the text box is a number thanks

Check If Variable Is A Number
Is there a function to check if the contents of a variable is a number?

Check If Divisible By A Number
Hi all, just a quick question...

What would be the easiest way to see if an integer is divisible by a number...

e.g.
if 4 is divisible by 2 = true
if 4 is divisible by 3 = false

just wondering if there is a VBfucntion that can help me cover this, or if i will have to do it mathmatically.

if any one has any ideas, they would be much appreciated.

Thank all,

Mojoinst

Check If Number Is Negative
How can I check if the integer is negative or not?

Check A Textbox For A Whole Number Value??
*sigh* I'm stuck.

I've a textbox I'm using for an App with a number keypad on it (like a calculator) and it is for Numbers only. I can't figure out how to make code to check to see if the number that's in it is a whole number or not?

Ex: txtNum.text contains 2400.78

If I press the . key again, I don't want it to insert another .
How can I test the value in the box for a whole number?

My brain is too tired to figure it out.

Help me out here you GooRoozzzz!

Edit: I'm actually Agent077. I found my old login password. I had forgotten it and couldn't get it back, due to the e-mail address for this account doesn't exist anymore.

Check For Prime Number..
how the porgram to check the prime number??
thanks...

Need Help With DO While Loop To Check If Number
Is there a way to do this without using the IsNumberic function?

Write a user defined Boolean function called MyIsNumber that behaves like the IsNumeric function to determine whether or not the textbox text property contains a number.

Use a Do While statement to loop through the characters in the string.

For this program, a number can be positive, negative (sign only in the first or last position) or unsigned, can contain only digits, and may or may not contain one decimal point (in any position). This is not the same definition that Microsoft uses.

Im finally stummped in my VB experience

Check If Number Is Integer?
How to check if number is Integer or not? Simple division calculation result below gives most of the cases floating point number, if this is the case, need to run calculation again.

Code:

Dim nFileHandle As Integer
Dim nShell As String
Const FILENAME = "C:division.txt"
Dim nLoopCount As Integer
Dim divCounter As Integer
divCounter = 0
nFileHandle = FreeFile
Open FILENAME For Output As #nFileHandle
line1:
Dim i As Integer
Randomize
i = Int(Rnd * 99) + 1

Dim j As Integer
Randomize
j = Int(Rnd * 9) + 1

If i < j Then GoTo line1

If i/j <> integer Then GoTo line1 'this doesn't work of course, but how to make it work?

MsgBox ("Division result is: " & i / j)
Print #nFileHandle, Format(i, "00"); "/"; Format(j, "0"); "="; i/j

If divCounter < txtDiv Then GoTo line1
Close #nFileHandle
nShell = Shell("notepad " & FILENAME, vbNormalFocus)

How To Check Number In Textbox ?
How to check number in text box after val(string) in textbox .thanks

How To Check For Database Number?
hi!,

how do u check for the database data number. I am using "Microsoft Access". This is what i want. I want to check if the database field size is what the user types in and display a message box if number in text box is higher than this. For example if the database field size for name is 20 and i have 21 text in text box then i want to display message box saying "Number is bigge".

how do u do this. Can u send me sample code. If u send me sample code can u plz explain what the code means.

Anyways plz let me know as soon as possible.

Thank you for ur help in this matter.

Check If A Returned Variant Is A Number?
Is there a function to check if a returned variant is a number? Sort of like the isnumber() function in excel spreadsheet

How To Check Whether A Value Obtained Is A Whole Number/integer
Hello,

How do I check whether a value obtained from a procedure is an integer or whole number?

Ways To Check If A Number Is Of Power 2
I'm looking for different ways (efficient ways) to check if a given number is a power of 2. If you have one that you know or have used please post it.

Thanks

Check File Version Number
hi
how do u check a version of a specific file?

Check Number Of Characters In Text Box
Anyone know how to do this? For exampel if i want to have a text box for the time and a submit button, how could i check if the text box is full when the user presses the button? I want to do this because if the user only enters "00:00" it wont work, they have to enter "00:00:00".

Maybe i could do something like this?:

Code:
Private Sub Command1_Click()
If Text1.length = 1 or Text1.length = 2 or text1.length = 3 (and so on) Then
MsgBox "fill the whole text box"
Exit Sub
End If
End sub

Thanks for any help i can get!!

Check If Textbox Text Is A Number?
Hi everyone?

How can know if a textbox text it΄s a valid number?

Thanks.

Database - Check To See If Card Number Is Already Being Used
i want to see if the database already has the gift card number, and if it does, give an error. if no, write the new gift card info to the databse

here is the code i am using:

VB Code:
'Register a new Gift Card    'On Error GoTo message    'Connect to database    strCNString = "Data Source=" & App.Path & "DATABASE.mdb"    cn.Provider = "Microsoft Jet 4.0 OLE DB Provider"    cn.ConnectionString = strCNString    cn.Properties("Jet OLEDB:Database Password") = ""    cn.Open    'Open recordsource    rs.Open "Select * from GiftCards", cn, adOpenDynamic, adLockOptimistic    'Ready recordsource for adding username and password    rs.AddNew    'Assign test boxes on form to their appropriate field in the recordsource    rs.Fields("CardAmount").Value = txtCardAmount.Text    rs.Fields("CardNumber").Value = txtCardNumber.Text    rs.Fields("Date").Value = Format(Date, "MM.DD.YYYY")    'Save record    rs.Update    'Close connections to database    rs.Close    cn.Close

How To Check If An Input In Textbox Is A Number ?
how to check if an input in textbox is a number ?

Check Random Number Code
I found this code to generate a random ID. But I'm not up on all the math biz in VB and wondered if someone more learned then I could tell me whats going on in the code and if the code would or could generate the same number twice?

VB Code:
'////// TIMEDATE MARKER //////////////////Function generateID()   Randomize     generateID = 1 & CInt(Rnd() * 10000)End Function

How To Check That A Number Is Negative Or Decimal???
i need to tell if the number in my textbox is a decimal or negative
how to change it first to a numeric since VB takes it as a string???
then do i use CDec?
ans for the negative number check?
pls help
thx!

Need To Check Number In A Temporary Field.
Hi everyone (first time poster)

I have a database in access and I am using access VBA.

heres my code

Code:

SQLStg = "SELECT Count(DriverClass.ClassID) AS CountClass"
SQLStg = SQLStg & " FROM DriverClass "
SQLStg = SQLStg & " WHERE DriverID = " & Me.DriverID
Set rec = db.OpenRecordset(SQLStg)
If rec.EOF Then
MsgBox "Warning, Driver must be entered in at least one class", , "Warning"
Else
End If

it is the if statement I am having trouble with. I want to write code that will see if the driver is in at least one class (count >0 ). The way the code is now, rec will always = 1 because the result of count needs to be put in a field.

I hope I was able to explain this. I am still quite new to Acess VBA. Thanks for your input and help.

Check If The Variable Is An Integer Number
How can I check If the result of calculation is an integer number?

Thank you for the help.

How To Check Number Of Difference Character In Data?
Dear all expert programmer,

I have data belew.
tmpstr = "abcd,bcdf,abcdef" <-- data is unlimit and separate by comma

I want to find number of difference character.
If I input 1 : result is "abcd,bcdf" because they have one difference character.

If I input 2 : result "abcd, abcdef" and "bcdf, abcdef" because they have two diffence character.

Please tell me how to code it.

Check Array Values For Highest Number
I have an array with 4 slots

Dim x(3)

I need to check the array to make sure at least 1 of the numbers in it is higher than all other numbers.

What is the most efficient way to do this?

Unable To Check Cell Value And Assign Number To Variable
Is there anything wrong with this?

I am trying to check if a box has a fill colour and if it does, add 1 onto the variable

Code:
Sub CollateTicks()

LastRow = LastRowInColumn(3)

Dim TicksWhite As Double
Dim TicksAmber As Double
Dim TicksGreen As Double
Dim TicksRed As Double

TicksWhite = 0
TicksAmber = 0
TicksGreen = 0
TicksRed = 0

For x = 8 To LastRow

Sheets("Critical Document Matrix").Select
Range("AA" & x).Select
If Selection.Interior.ColorIndex = 3 Then
TicksRed = TicksRed + 1

If Selection.Interior.ColorIndex = 44 Then
TicksAmber = TicksAmber + 1

If Selection.Interior.ColorIndex = 43 Then
TicksGreen = TicksGreen + 1

If Selection.Interior.ColorIndex = xlNone Then
TicksWhite = TicksWhite + 1

End If
End If
End If
End If

Sheets("Critical Document Matrix").Select
Range("AB" & x).Select
If Selection.Interior.ColorIndex = 3 Then
TicksRed = TicksRed + 1

If Selection.Interior.ColorIndex = 44 Then
TicksAmber = TicksAmber + 1

If Selection.Interior.ColorIndex = 43 Then
TicksGreen = TicksGreen + 1

If Selection.Interior.ColorIndex = xlNone Then
TicksWhite = TicksWhite + 1

End If
End If
End If
End If

Sheets("Critical Document Matrix").Select
Range("AC" & x).Select
If Selection.Interior.ColorIndex = 3 Then
TicksRed = TicksRed + 1

If Selection.Interior.ColorIndex = 44 Then
TicksAmber = TicksAmber + 1

If Selection.Interior.ColorIndex = 43 Then
TicksGreen = TicksGreen + 1

If Selection.Interior.ColorIndex = xlNone Then
TicksWhite = TicksWhite + 1

End If
End If
End If
End If

Sheets("Critical Document Matrix").Select
If Selection.Interior.ColorIndex = 3 Then
TicksRed = TicksRed + 1

If Selection.Interior.ColorIndex = 44 Then
TicksAmber = TicksAmber + 1

If Selection.Interior.ColorIndex = 43 Then
TicksGreen = TicksGreen + 1

If Selection.Interior.ColorIndex = xlNone Then
TicksWhite = TicksWhite + 1

End If
End If
End If
End If

Sheets("Critical Document Matrix").Select
Range("AE" & x).Select
If Selection.Interior.ColorIndex = 3 Then
TicksRed = TicksRed + 1

If Selection.Interior.ColorIndex = 44 Then
TicksAmber = TicksAmber + 1

If Selection.Interior.ColorIndex = 43 Then
TicksGreen = TicksGreen + 1

If Selection.Interior.ColorIndex = xlNone Then
TicksWhite = TicksWhite + 1

End If
End If
End If
End If

Sheets("Critical Document Matrix").Select
Range("AF" & x).Select
If Selection.Interior.ColorIndex = 3 Then
TicksRed = TicksRed + 1

If Selection.Interior.ColorIndex = 44 Then
TicksAmber = TicksAmber + 1

If Selection.Interior.ColorIndex = 43 Then
TicksGreen = TicksGreen + 1

If Selection.Interior.ColorIndex = xlNone Then
TicksWhite = TicksWhite + 1

End If
End If
End If
End If

Sheets("Critical Document Matrix").Select
Range("AG" & x).Select
If Selection.Interior.ColorIndex = 3 Then
TicksRed = TicksRed + 1

If Selection.Interior.ColorIndex = 44 Then
TicksAmber = TicksAmber + 1

If Selection.Interior.ColorIndex = 43 Then
TicksGreen = TicksGreen + 1

If Selection.Interior.ColorIndex = xlNone Then
TicksWhite = TicksWhite + 1

End If
End If
End If
End If

Next x

Sheets("Maturity Dashboard").Select
Range("C28").Select
ActiveCell.FormulaR1C1 = TicksWhite

Sheets("Maturity Dashboard").Select
Range("C29").Select
ActiveCell.FormulaR1C1 = TicksAmber

Sheets("Maturity Dashboard").Select
Range("C30").Select
ActiveCell.FormulaR1C1 = TicksRed

Sheets("Maturity Dashboard").Select
Range("C31").Select
ActiveCell.FormulaR1C1 = TicksGreen

End Sub

Check The Actual Hard Drive Serial Number
Marty, (or others)

I designed my program to check the serial number of the hard drive at startup and compare it with the contents of a file, if it matches the program runs, if not, it asks for an unlock code. My problem is that I mistakenly checked the Volume Serial Number instead of the actual hard drive serial number, so now a hard-drive can be cloned (using Norton Ghost, etc.) and be loaded onto another computer without problems.

I found code to check the actual serial number of the hard drive but it requires admin access (original code was titled HDDSerial.zip, but I can't seem to find the message it came from...) If a standard user runs the program the "hard drive serial check" fails because he's not an administrator.

Do you know of any way to check the actual hard drive serial number without requiring admin access?

Jason

Anybudy Know How To Check How Many Times A Number Is Occure In My Array?
Hi friends,,,
i got a small problem...is am using the following code to store values fom a spreadsheet...now i want to find out tha which number is coming how many time, basically i wants to check that is there any number in my array more than once or not...how i can check this???

Dim iam, MyArray(39) As Integer
For SRow = 4 To 43
MyArray(SRow - 4) = oExcel.Cells(SRow, 6).value
Next

Checkbox..... Check Check Check Check Check...oops Stack Error
I have three check boxes one on each of my SSTab tabs. If one is checked the other two needs to be unchecked.... and so on. I use this to determine which is the default website. Ok....here is the code I used....

Select Case Index
Case 0
chkDefaultWebsite(1).Value = vbUnchecked
chkDefaultWebsite(2).Value = vbUnchecked
' Case 1
chkDefaultWebsite(0).Value = vbUnchecked
chkDefaultWebsite(2).Value = vbUnchecked
Case 2
chkDefaultWebsite(0).Value = vbUnchecked
chkDefaultWebsite(1).Value = vbUnchecked
End Select

Simple enough right? Well the first time I click on the check box, my box isn't checked but my others are unchecked....so when I click again it checks it..... so I did this....

Select Case Index
Case 0
chkDefaultWebsite(0).Value = vbChecked
chkDefaultWebsite(1).Value = vbUnchecked
chkDefaultWebsite(2).Value = vbUnchecked
Case 1
chkDefaultWebsite(0).Value = vbUnchecked
chkDefaultWebsite(1).Value = vbChecked
chkDefaultWebsite(2).Value = vbUnchecked
Case 2
chkDefaultWebsite(0).Value = vbUnchecked
chkDefaultWebsite(1).Value = vbUnchecked
chkDefaultWebsite(2).Value = vbChecked
End Select

And of course I get a stack error of endless days err...I mean looping on the check box.....

How can I get that to check the first time I click on it and also uncheck the others ???

Thanks again !

Counting Number Of Checked Check Boxes In A Control Array
Hi everybody,

I have a program which calculates a total

there are 3 check box in a control array

I need to count the number of "checked" check boxes in the array and multiply that value obtained by a variable (zor)

I know the code for counting check boxes (whether checked or uncheked)

eg the msgbox will give the no. of check boxes

Code:
private sub cmdgo_click()
end sub

but i need some code single piece which will give me no of check boxes that have been checked ?

Hope I will get an answer

Thanks

Password Field Check If Number && Alphabet && Special Character Exists Using Instr()
hello every body,
While choosing a new password a user should be forced to have a combination of number & alphabet & special character. I tried the following code using instr(). But for some reason I continue to get "invalid password" inspite of the fact all the three are there.

Code:
Private Sub Command1_Click()
Dim numberExists As Boolean, alphabetExists As Boolean, specialCharacterExists As Boolean, allExists As Boolean
numberExists = False
alphabetExists = False
allExists = False
specialCharacterExists = False

If InStr(1, "1234567890", Me.Text1) > 0 Then
numberExists = True
Else
numberExists = False
End If
If InStr(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", Me.Text1) > 0 Then
alphabetExists = True
Else
alphabetExists = False
End If
If InStr(1, "!@#\$%^&*", Me.Text1) > 0 Then
specialCharacterExists = True
Else
specialCharacterExists = False
End If

If numberExists = True And alphabetExists = True And specialCharacterExists = True Then
Else
End If

End Sub

can somebody pinpoint the error...

Give A Command Button A Different Function Based On Number Of Check Boxes Checked?
I have 20 check boxes on a form, as well as a command button. What I want to happen when the command button is pressed is display an alert when the number of check boxes checked are 10 or more. If 9 or less check boxes are checked, a different alert should be displayed. What would be the code for the command button?

This is in Visual Basic 5.

Check Script Needed (Powerpoint: Check For Active Presentation}
I have a small problem with my powerpoint addin.
I want to have a optionbutton that is enabled as soon as powerpoint have an active window. (else the optionbutton is disables)

But i don't know how to make that.

plz help, thnx

Check If Combobox Has No Values Inside It And Check If Listview Is Empty
Hi, i need to do a check like this

If Nothing is in the combobox then
function
else
lala
end if

and

if nothing is in the listview then
function
else
lala
end if

(when i said in the combobox, i mean in the list. not the value of combobox.text)

thanks!!

Is There Any Built In Method To Convert Decimal Number To Binary Number In V.b 6.0
Hi everybody!

can u say whether any built in method is available to convert a given decimal number to binary number?

i can develope a user defined method for this. but i think it takes some extra time to execute... since i have to call this method repetedly...

thank you,
Regards:

Text1 Number &gt; Text2 Number Error After 2 Digis Use(solved)
Umm, this a weird error it I amtrying to compare two numbers in each box,

so it will be something like this

If text1 > text2 then
msgbox "too large"
End if

But the weird thing is after the number hit two digits lets say over 10 and up then I get errors, even if the number in text2 is larger this only happens after it goes over 10

weird is there a better wayt to compare number that is more reliable or do i need to add something to the code

Thanks

Retrieve Hard Disk Serial Number Using VB [Not Volume Number]
I need help in reading the Hard Disk Serial Number [Not the volume number] using VB. Currently I am using VB5.

I have found a site that has the program to read the serial number but it is written in C++.

Can anyone convert it to a DLL or has any other solution for it.

The site is http://www.winsim.com/

Thank you.