Results 1 to 11 of 11

Thread: Option Strict Errors FIGURED OUT

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131

    Question Option Strict Errors FIGURED OUT

    My program works fine with option strict off but my instructor says it has to be on. Can someone tell me why I'm getting errors and how to fix them?? My errors all say Option Strict On disallows implicit conversions from 'Double' to 'String'. I highlighted where I'm getting the errors. And when I change when I change the grpSalespersons.Text to SP, grpTotalSales.Text to TS, and grpAverageSales.Text to AV; the errors go away but my program doesn't work anymore. Please help!

    ' Set up constants for Base pay(BP) = $500 and commission(CM) is 6%
    Const BP As Double = 500.0
    Const CM As Double = 0.06

    Dim SA As Double
    Dim GP As Double
    Dim SP As Double
    Dim TS As Double
    Dim AV As Double

    Private Sub btnGross_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGross.Click
    SA = Val(nudSales.Text)
    SP = Val(grpSalespersons.Text)
    TS = Val(grpTotalSales.Text)
    AV = Val(grpAverageSales.Text)
    ' Compute value and display in Gross Pay
    GP = BP + SA * CM
    txtGross.Text = Format(GP, "$#####0.00")
    ' Compute value and display in Salespersons
    grpSalespersons.Text = SP + 1
    ' Compute value and display in Total Sales
    grpTotalSales.Text = SA + TS
    ' Compute value and display in Average Sales
    grpAverageSales.Text = TS / SP
    End Sub
    Last edited by twisted; Jun 8th, 2004 at 09:03 AM.
    Twisted

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    SP is a double..... SP + 1 is still a double. A Textbox is a string.... you have to conver the number to a string......

    grpSalespersons.Text = (SP+1).ToString

    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??? *

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by techgnome
    SP is a double..... SP + 1 is still a double. A Textbox is a string.... you have to conver the number to a string......

    grpSalespersons.Text = (SP+1).ToString

    TG
    I don't think that twisted is bothering to read our posts. Have a look at all his previous posts and you will find he is using VB6, but he keeps ignoring us and posts in this Forum. (As well as posting it in the Classical VB section )
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153

    Re: Option Strict Errors

    Originally posted by twisted
    Private Sub btnGross_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGross.Click
    Been a very long time since I did ordinary VB at Uni, so I may be wrong but doesn't VB use variant and doesn't have events or handlers? Even still he shouldn't be posting in the ordinary vb forum in that case.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Well, VB6 doesn't have the Option Strict setting, at least not that I am aware of.... I thought that was added to .NET specifically to allow VB6 developers to "feel comfortable" with implicit conversion.

    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??? *

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

    Re: Re: Option Strict Errors

    Originally posted by Carnifex
    Been a very long time since I did ordinary VB at Uni, so I may be wrong but doesn't VB use variant and doesn't have events or handlers? Even still he shouldn't be posting in the ordinary vb forum in that case.
    Yes, VB6 has variants, yes VB6 has event and event handlers.... but the code he's posted is clearly VB.NET....

    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??? *

  7. #7
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    My bad wording there, I meant variant instead of object .

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Guys I am using VB.Net I just posted in VB6 before I upgraded. Thanks for the help it worked like a charm. I knew what I needed to do but am such a beginner it is killing me. If you guys get a chance check out the other post by me. Can't seem to figure it out. Thanks again!
    Twisted

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    HI techgnome,

    "Yes, VB6 has variants, yes VB6 has event and event handlers.... but the code he's posted is clearly VB.NET...."


    It is NOW. But it wasn't before he edited it. He was treating TextBox.Text as a variant.

    Anyway, he has since confirmed he is working in VB.NET, but have a look at all his recent posts and you will see what I mean (including the one on Classical VB).
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  10. #10
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by twisted
    Guys I am using VB.Net I just posted in VB6 before I upgraded. Thanks for the help it worked like a charm. I knew what I needed to do but am such a beginner it is killing me. If you guys get a chance check out the other post by me. Can't seem to figure it out. Thanks again!
    Right. I can now see where you are coming from. You are trying to carry on with VB6 coding in .NET. Hence the problems with previous posts. Looks like your instructor is deliberately trying to emphasise this. Best of luck
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Alright thanks man! I appreciate any help I can get!
    Twisted

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