Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 14th, 2013, 07:03 PM
dabadguy4273 dabadguy4273 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 dabadguy4273 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 8 sec
Reputation Power: 0
Question Just a little help plz c:

Alright so, i'm new to Visual Basic and i'm trying to make just a simple program that tells you if the number entered in the text box is positive or negative when you click the button. I'm not sure if the code i put on the button is wrong or if nothing I did was right xD Here's the code for the button.

Sub checkposneg()
If text1 <= 0 Then Print "Positive"
If text1 >= 0 Then Print "Negative"
End Sub

and i'm pretty sure that almost none of it is right xD

Reply With Quote
  #2  
Old January 14th, 2013, 08:39 PM
portcitysoftwar portcitysoftwar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 163 portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 13 h 18 m 54 sec
Reputation Power: 17
What visual basic are you using VB6, VB.NET, VB Script?

I havnt ever written any command line VB only windows with a gui. I am assuming your writing console application with your use of "print" . Yet you also say you are using a textbox which would mean GUI?

Either way with VB.net
Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
if (convert.todecimal(textbox1.text)>=0) THEN
label1.text="positive"
ELSE
label1.text="negative"
END IF
End Sub


Quote:
Originally Posted by dabadguy4273
Alright so, i'm new to Visual Basic and i'm trying to make just a simple program that tells you if the number entered in the text box is positive or negative when you click the button. I'm not sure if the code i put on the button is wrong or if nothing I did was right xD Here's the code for the button.

Sub checkposneg()
If text1 <= 0 Then Print "Positive"
If text1 >= 0 Then Print "Negative"
End Sub

and i'm pretty sure that almost none of it is right xD

Reply With Quote
  #3  
Old January 14th, 2013, 09:23 PM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 165 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 16 h 26 m 48 sec
Reputation Power: 43
Quote:
Originally Posted by dabadguy4273
Alright so, i'm new to Visual Basic and i'm trying to make just a simple program that tells you if the number entered in the text box is positive or negative when you click the button. I'm not sure if the code i put on the button is wrong or if nothing I did was right xD Here's the code for the button.

Sub checkposneg()
If text1 <= 0 Then Print "Positive"
If text1 >= 0 Then Print "Negative"
End Sub

and i'm pretty sure that almost none of it is right xD

What you have to appreciate is that the contents of a TextBox are treated as a Variant. Since you are entering text, the variant will be treated as text, but what you are after is the numerical value. Create a new project and add a text box (default name Text1) and a CheckBox (default name Check1). Change the text property of Text1 to (blank), and Change the Caption property of Check1 to "Positive". Add the following code:
Code:
Function CheckPos(vNum As Variant) As Boolean
    If Val(vNum) >= 0 Then
        CheckPos = True
    Else
        CheckPos = False
    End If
End Function


Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If CheckPos(Text1.Text) Then
            Check1.Value = 1
        Else
            Check1.Value = 0
        End If
    End If
End Sub

I have renamed the subroutine "checkposneg" that you wrote to a function "CheckPos" so that it will return a value. When you enter a number in the text box and hit the Enter key, it will call the function and the function will check the value of the text and return either "True" or "False". That value is used to set the Check Box.

J.A. Coutts

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Just a little help plz c:

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap