Results 1 to 26 of 26

Thread: problem programing with vb.net for pocket pc

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Exclamation problem programing with vb.net for pocket pc

    hi,

    i am trying to make a program to do equations... and i cannot get any command line to work i am used with vb6 command line and i guess the .net ones are different...

    i have this code so far:

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim txttest As Integer
    txttest = 1234
    End Sub
    End Class

    i made it to test my command so when i press on the button, the numbers 1234 are supposed to show on the textfield (txttest)... but nothing happens when i press on the button... can someone help me please?

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: problem programing with vb.net for pocket pc

    Hi,
    sure you aren't getting an error as the line should read
    txttest.text = "1234"

    In VB.Net there is no default property, so you need to use the .text property

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: problem programing with vb.net for pocket pc

    Where are you showing the number? What you have shown in the code is filling a variable, but at no time do you put the number into a label, textbox, or any other control. Where did you want it to display?
    My usual boring signature: Nothing

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: problem programing with vb.net for pocket pc

    Quote Originally Posted by petevick
    Hi,
    sure you aren't getting an error as the line should read
    txttest.text = "1234"

    In VB.Net there is no default property, so you need to use the .text property

    Pete
    While I rarely disagree with Pete, he overlooked something here. txttest is declared in the sub as a variable of type integer. If there is also some control with that name on the form, then the local declaration in the sub will shadow the control and cause trouble.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Re: problem programing with vb.net for pocket pc

    well... i showed the number just because my button for the equation was not working... so i was trying to see if the button was working at all... without success... here is the code i really want as a final product:
    Code:
    dim lbltps as integer
    dim lbltvq as integer
    dim txtavtaxes as integer
    dim txtaptaxes as integer
    lbltps = txtavtaxes * 0.05
    tps2 = txtavtaxes * 1.05
    lxbltvq = tps2 * 0.075
    txtaptaes = lbltvq + tps2
    lbltvq = Format(lbltvq, "0.00")
    lbltps = Format(lbltps, "0.00")
    txtavtaxes = Format(txtavtaxes, "0.00")
    txtaptaxes = Format(txtaptaxes, "0.00")
    so... when i press on a button it will do all those calculs... this was orginally a vb6 code that i am trying to port into a windows mobile device.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: problem programing with vb.net for pocket pc

    That wouldn't work in VB6 either, for the same reasons... You have created variables with the same names as the controls, and are putting the values into the variables - not the controls.

    Remove the Dim's for items that have the same names as your controls.


    You will probably then get an error due to what Pete mentioned, as you apparently have what is considered to be a bad habit for VB6, and is not valid for VB.Net (not specifying which property you want to use).

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Re: problem programing with vb.net for pocket pc

    alright, so i remove the dim for my textbox and label...

    all the values are monetary numbers... for example: 99.02... what do i put?

    for lbltps i'd write for example:

    txtavtaxes.text=txtavtaxes.texte*0.05


    is that right or i understood it wrong?

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: problem programing with vb.net for pocket pc

    That will only work if you have Option Strict OFF, which is a bad habit to get into (though one I had for a year or two, so I won't be throwing any stones). The proper way to write that would be something like this:

    txtavtaxes.Text = (cdbl(txtavtaxes.Text)*0.05).ToString

    That probably looks considerably more wordy than what you wrote, but the only difference is that I am explicitly telling the compiler to convert the string in the the txtavtaxes textbox .Text property into a double, then perform the computation, then turn the result back into a string to put into the other textbox. Your code would do that implicitly, but doing it implicitly is not as fast. Worse, in some situations (though not this one), doing implicit conversions can lead to really odd and puzzling bugs. For these two reasons, turning Option Strict ON is a good habit, despite the fact that it will force you to write a bit more code.

    One other point I should make is that if txtavtaxes.Text is not a valid number, then CDbl will raise an exception, but so would your code. There are a few safer ways to do the conversion, but they take more code. One option would be this:
    vb Code:
    1. Dim d as double
    2.  
    3. if Double.TryParse(Txtavtaxes.Text,d) then
    4.   txtavtaxes.Text = (d * 0.05).ToString
    5. Else
    6.   'Whatever was in the textbox could not be converted to a double.
    7.   txtavtaxes.Text = 0
    8. End if
    My usual boring signature: Nothing

  9. #9
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: problem programing with vb.net for pocket pc

    Sorry - didn't read the code properly - been a long day

    I assumed that something starting with txt*** was a text box - never assume

    You could always do ....

    txtavtaxes.Text = (cdbl(val(txtavtaxes.Text))*0.05).ToString

    which should work without errors, although not necessarily give the correct result.
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: problem programing with vb.net for pocket pc

    Yeah, that would work. You wouldn't even need the cdbl in that example. Of course, if the value in the textbox was not a number then the answer would always be 0.
    My usual boring signature: Nothing

  11. #11

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Re: problem programing with vb.net for pocket pc

    perfect, it is working! now i am trying to find a way to round the results to the second digits after the .

    (for example, the answer is 87.837, it will display 87.84)


    Quote Originally Posted by petevick
    Sorry - didn't read the code properly - been a long day

    I assumed that something starting with txt*** was a text box - never assume

    You could always do ....

    txtavtaxes.Text = (cdbl(val(txtavtaxes.Text))*0.05).ToString

    which should work without errors, although not necessarily give the correct result.

  12. #12

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Re: problem programing with vb.net for pocket pc

    oh and 1 last thing that i am looking for:
    i want that, when i click in the textbox, it changes all the labels to nothing.. in vb the code was, for example the label is called lbltest:

    the command would be:
    lbltest=""

    what is the equivalent in vb .net?

    thnx a lot!

  13. #13
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: problem programing with vb.net for pocket pc

    Hi,
    look at the 'format' property.

    In vb.Net there is no default property, so it would be...
    lbltest.text = ""

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  14. #14

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Re: problem programing with vb.net for pocket pc

    thnx for all the answers, the last thing i am confused with is how to round to the second digit after the .

    for example: lbltest = 192.88993

    so, lbltest would only show: 192.89

    any idea for that last code?

  15. #15
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: problem programing with vb.net for pocket pc

    Did you look at 'format'?

    in 'old' vb
    Format (lblText.text,"###0.00")
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  16. #16

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Re: problem programing with vb.net for pocket pc

    Quote Originally Posted by petevick
    Did you look at 'format'?

    in 'old' vb
    Format (lblText.text,"###0.00")
    yeah i knew about that code in vb6, but it is not working on vb .net... anyone know another code?

  17. #17

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Question Re: problem programing with vb.net for pocket pc

    one last thing, i am trying also to create the file so i can put in on my pocket pc.... and when i press build it is creating some kind of .exe file... is it possible to create a setup file or a cab file so i can install the program on my device and is it possible to install automatically the .net mobile framework with the installation file??

  18. #18
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: problem programing with vb.net for pocket pc

    look for 'deploy' or 'deployment' on this forum - loads of entries showing how to make a setup project
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  19. #19
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: problem programing with vb.net for pocket pc

    Apparently you can't round a double, but you can round a decimal nicely. Since the two are very close, try this:

    Assuming you have the value in a double called d

    lblTest.Text = Decimal.Round(CDec(d),2).ToString

    Decimal.Round will do the rounding, but it may not accept a double (it certainly won't if Option Strict is ON), so I explicitly cast it to a Decimal type. Oddly, the tooltip help that shows up for Decimal.Round suggests that you can only get an integer from that method, but that's true only for one of the four different versions of the method. If you pass it a decimal and an integer, as I am doing, then it rounds the decimal to the number of decimal places specified in the integer argument.
    My usual boring signature: Nothing

  20. #20

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Re: problem programing with vb.net for pocket pc

    Quote Originally Posted by Shaggy Hiker
    Apparently you can't round a double, but you can round a decimal nicely. Since the two are very close, try this:

    Assuming you have the value in a double called d

    lblTest.Text = Decimal.Round(CDec(d),2).ToString

    Decimal.Round will do the rounding, but it may not accept a double (it certainly won't if Option Strict is ON), so I explicitly cast it to a Decimal type. Oddly, the tooltip help that shows up for Decimal.Round suggests that you can only get an integer from that method, but that's true only for one of the four different versions of the method. If you pass it a decimal and an integer, as I am doing, then it rounds the decimal to the number of decimal places specified in the integer argument.
    when i try this code, i get an error message:
    Error 1 Name 'd' is not declared.

    also, another code i am looking for: to change a caracter for another...
    for example: someone write 87.29 it will change the . for a , automatically... so it would write 87,29 instead of 87.29...

  21. #21
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: problem programing with vb.net for pocket pc

    Format statement is still supported in .Net - try
    Code:
    format(cdbl(lbltext.text),"##0.00")
    Replace would change the . for a , but the decimal char depends on the culture used on the device, so in the UK it would be . but in Spain it would be ,
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  22. #22

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Re: problem programing with vb.net for pocket pc

    Quote Originally Posted by petevick
    Format statement is still supported in .Net - try
    Code:
    format(cdbl(lbltext.text),"##0.00")
    Replace would change the . for a , but the decimal char depends on the culture used on the device, so in the UK it would be . but in Spain it would be ,

    i dont get any error message now but the command doesnt seem to change anything...

    here is the full code:

    Private Sub btajtaxes_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btajtaxes.Click
    Dim tps2 As String
    lbltps.Text = (CDbl(txtavtaxes.Text) * 0.05).ToString
    tps2 = (CDbl(txtavtaxes.Text) * 1.05).ToString
    lbltvq.Text = (CDbl(tps2) * 0.075).ToString
    txttotal.Text = (CDbl(lbltvq.Text) + tps2).ToString
    Format(CDbl(lbltvq.Text), "##0.00")
    End Sub

  23. #23
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: problem programing with vb.net for pocket pc

    tps2 shouldn't be a string.... dim it as a double... or decimal...

    then eliminate the .ToStyring on the second calculation (where you set tps2).

    also, some of your calculations are unnecessary...
    Code:
    Private Sub btajtaxes_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btajtaxes.Click
      Dim tps2 As Decimal = CDbl(txtavtaxes.Text) * 1.05
      lbltps.Text = tps2.ToString
      lbltvq.Text = (tps2 * 0.075).ToString("##0.00")
      txttotal.Text = (tps2 * 1.075).ToString
    End Sub
    fyi = Format is a function, so it returns a value... it doesn't actually DO the formating.... but the code above eliminates it anyways.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  24. #24

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    11

    Re: problem programing with vb.net for pocket pc

    Quote Originally Posted by techgnome
    tps2 shouldn't be a string.... dim it as a double... or decimal...

    then eliminate the .ToStyring on the second calculation (where you set tps2).

    also, some of your calculations are unnecessary...
    Code:
    Private Sub btajtaxes_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btajtaxes.Click
      Dim tps2 As Decimal = CDbl(txtavtaxes.Text) * 1.05
      lbltps.Text = tps2.ToString
      lbltvq.Text = (tps2 * 0.075).ToString("##0.00")
      txttotal.Text = (tps2 * 1.075).ToString
    End Sub
    fyi = Format is a function, so it returns a value... it doesn't actually DO the formating.... but the code above eliminates it anyways.

    -tg

    it is working perfectly for lbltps! cool!
    but when i try to add the same kind of code for the other fields

    (i need to do the same thing for txtavtaxes.text, lbltps.text an d txttotal.text so it will change the . for a , and it will put only 2 digits after the ,)

  25. #25
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: problem programing with vb.net for pocket pc

    Show us the code that is not working.

    By the way, my example with Decimal.Round assumed that you had a variable named d declared. That was just an example, had you put any other double variable in place of d, the code would work. Since you have now defined tps2 as type Decimal, you can now use Decimal.Round(<your decimal variable>,2) to get two decimal places. However, it looks like TechGnome has an easier formatting solution.
    My usual boring signature: Nothing

  26. #26
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: problem programing with vb.net for pocket pc

    as for the rest of your calculations, samethign... do all your calculations on numerical datatypes (decimal, double, integer, etc) as much as you can. ONLY convert to string WHEN you are ready to put your result somewhere you need it to be a string. don't try to convert things to/from strings during the calculations. that only slows things down and gets confusing.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width