if isnumeric(txtAntall.text) then if txtAntall.text >= 0 then msgbox "Tallet er positivt" else msgbox "Tallet er negativt" end if else msgbox "Det indtastede er ikke et tal" end if
Du kan også bruge en _KeyPress event til at forhindre, at der tastes andet end 0-9 ind:
Text1_KeyPress(KeyAscii As Integer) ' Checker om tast er et numerisk tastetryk ' tallene 0-9 samt <Backspace> accepteres ' <Enter> laves om til <Tab>
Select Case KeyAscii Case vbKeyBack, 48 To 57 'Tallene 0-9 og backspace Case vbKeyReturn KeyAscii = 0 SendKeys "{tab}" Case Else KeyAscii = 0 MsgBox "Indtast kun tal", vbExclamation End Select End Sub
Herefter kan du så bruge
If Not Text1.Text > 0 then MsgBox "Tal skal være større end nul" End if
/Martin
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.