change to one decimal place

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maharajakecil
    New Member
    • Mar 2008
    • 12

    change to one decimal place

    hello VB expertise. how should i modify my source code if i want change my X and Y value into one decimal place like 1.2,1.3,1.4 and so on. thank for the help. i really appreciate it!

    [code=vb]
    Private Sub Form_Load()
    Dim Xvalue As Long
    Dim Yvalue As Long

    For Xvalue = 0 To 15
    cboXvalue.AddIt em CStr(Xvalue)
    Next Xvalue

    cboXvalue.ListI ndex = 0

    For Yvalue = 0 To 15
    cboYvalue.AddIt em CStr(Yvalue)
    Next Yvalue

    cboYvalue.ListI ndex = 0

    MSComm1.CommPor t = 1

    MSComm1.Setting s = "9600,N,8,1 "

    MSComm1.DTREnab le = False

    MSComm1.PortOpe n = True

    End Sub

    Private Sub cmdSend_Click()
    Dim Xvalue As Long
    Dim Yvalue As Long

    Xvalue = cboXvalue.ListI ndex
    Yvalue = cboYvalue.ListI ndex

    MSComm1.Output = Chr$(255) & Chr$(Xvalue) & Chr$(Yvalue)

    End Sub
    Private Sub Form_Unload(Can cel As Integer)
    MSComm1.PortOpe n = False
    End Sub[/code]
    Last edited by debasisdas; Mar 31 '08, 06:02 AM. Reason: added code=vb tags
  • Robbie
    New Member
    • Mar 2007
    • 180

    #2
    You can use the Format() command.
    StringOfYourNum ber = Format(YourNumb er, "0.0")

    "0" represents a digit that will always be shown. It's like padding a number. "#" represents a digit that will be shown if it needs to be shown.

    So...
    Format(0.1, "#.#") gives ".1".
    Format(0.1,"000 0.000") gives "0000.100".

    I suggest you play around with Format(), I think you'll find it very useful. ;)

    HOWEVER! Later on, I see you using Chr() on your number. Chr() needs whole numbers. Numbers with a fractional value will be rounded to the nearest whole number, so it won't make a difference whether there is or isn't anything after the decimal point in this case...

    Comment

    Working...