none
VB.NET sw stops when assigns True or False to boolean variable at runtime RRS feed

  • Question

  • Hello to everybody.

    I am not a skilled programmer, but I use VB.net when I develop the SW for the test of company hardware boards.

    Generally I find replies and solutions from the internet community at my problems met during the drafting of the code.

    This time is different, the SW works fine on the most of computers but when I tried to run it on a couple of different Lenovo notebooks the program stops at the run time with the message "cannot execute the program". Also my laptop is Lenovo and it works fine.

    All the pc have Windows 7 installed and at least .NET Framework 4.6.1. The pre-requisite is .NET Framework 4.6

    The VB instruction line where the SW stops is a stupid simple assignment...

    The variable is declared in a module and it is global

    Public bIsBatTest as Boolean = False 'assignment would not be necessary, False is the default value 

    Then the code is:

    Private Sub rdBtn1_CheckedChanged(sender As Object, e As EventArgs) Handles rdBtn1.CheckedChanged
            grpCHG.Visible = False
            grpDATA.Visible = False
            rdBtn1.Font = New Font(rdBtn1.Font, FontStyle.Bold)
            rdBtn2.Font = New Font(rdBtn2.Font, FontStyle.Regular)
            bIsBatTest = False   'this is the instruction where SW stops at runtime
            cmdNEW.Text = My.Resources.sNEWBRD
        End Sub

    To be sure I have put MsgBox just before and after: the msg before is shown, then the program stops.

    If I comment the line, SW runs until next assignment bIsBatTest = .....

    What's wrong in the code or, like I guess, in the 2 pc where the issue appears?

    Thanks a lot for any help

    Maurizio

    Monday, October 22, 2018 2:34 AM

All replies

  • Hi,

    As you said, you tried to run it on a couple of different Lenovo notebooks the program stops at the run time with the message "cannot execute the program".

    Direct error at runtime?You haven't triggered the CheckedChanged event for rdBtn1 yet?

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 22, 2018 5:11 AM
  • Hello Alex, thanks for your time.

    Yes, I know everything works because on my laptop and on other several pc (Lenovo, Acer, HP ...) the sw works as it shall do.

    The issue is just on a couple of other PC, but what drives me crazy is the error which is not when the code attempts to  access to calendar or excel file or SMTP server or Encryption server, it crash only when a Boolean variable is assigned to a True or False, but only at the run time.

    I tried to trap the error using Try-catch but it doesn't trap that error.

    I explained in my previous msg that I am sure the problem is exactly in that instruction line.

    I surfed on web to look for similar situations, but I have not found similar issues.

    This forum is my last hope.

    bye

    Maurizio


    • Edited by m.bonelli Monday, October 22, 2018 5:25 AM
    Monday, October 22, 2018 5:25 AM
  • mb,

    0. Remove all try/catches.

    1. Can you run any vb app on the problem system? Try an empty one form project that does nothing. If it runs then remove the part of your app that errs and run and see. Do this until you remove something and it runs. Then you know you just removed the problem.

    2. Is your deveopment system set to break on erros see step 2 here:

      http://sandiasoftware.com/vb.net%20depot/Visual%20Studio%20Tips.htm


    3. Is the anti virus blocking on the problem system?

    4. Is there any language difference or etc between the systems?

    5. Is the exact font available on the problem system including bold versions? I have had funny problems when a bold version of arial narrow was not on the system.


    6. Put lines in the code to verify all is well and check values etc ie


       rdBtn2.Font = New Font(rdBtn2.Font, FontStyle.Regular)

       msgbox("Step 1 bIsBatTest = " & bIsBatTest.tostring & rdBtn2.Font.tostring)


       bIsBatTest = true


       msgbox("Step 3 ok)


    7. Run the app in the VS ide on the problem system. Look for errs.

    8. What complile settings ie what cpu? try x86 and any. What chip is it on the problem system?

    9. What is differ ent between the problem system and your development system? ie software installed, What version of windows, monitor settings in control panel,  etc.


    Monday, October 22, 2018 9:06 AM
  • Do you have code in your load event?  Tommy alluded to this, the error might be happening in the Load event on a 64 bit machine and being swallowed, which causes an error down the line.

    Make your build / compile be x86, not Any CPU.


    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."

    - from former MSDN User JohnWein

    SerialPort Info

    Multics - An OS ahead of its time.

    Monday, October 22, 2018 3:18 PM
  • Hi dbasnett,

    Yes, I have a code in the load event and it changes the rdBtn1 checked status, rising the event.

    Like I have told before, if I comment the instruction bIsBatTest=False, the sw works fine, loading the form and go ahead until I will rise an event which changes the bIsBatTest flag again (to True or False).

    I have tried your suggestion, because simplest but unfortunately also compiled for x86 has the same behavior. And the same error also if compiled for Any CPU with prefer 32 bit checked (I was not expecting a different result, really :()

    The sw has a resource.dll in Chinese, but it is working fine on all computers of the company except those 2 or 3 laptops.

    To be honest is not a big issue, but I want to be sure to do not have that issue when we give the test SW to our outsourcer which manufacture the mass production because I deploy the sw by clickonce on a server to have the automatic updates, thus I am sure they use the latest build!

    Thanks for your help, I do what Thomas ask me ....

    Bye



    • Edited by m.bonelli Tuesday, October 23, 2018 1:54 AM
    Tuesday, October 23, 2018 1:49 AM
  • Hi Tommy,

    thanks for your help. Please, see below.

    0. I removed already, it doesn't work and it was not in the original code

    1. Yes, the form load and if I remove the instructions which assign the Boolean value, the sw runs as expected (but of course the behavior is like bIsBatTest = False (the default value when created).

    2. Yes, all that I set, but on the development machine I do not have any issues.

    3. I have thought the same and I removed the antivirus and restarted the machine. No effect, error still the same.

    4. I am Italian working in Beijing :). Development machine OS is Windows 7 Ultimate SP1, Chinese native with windows6.1-kb2483139-x64-en-us language pack. Target machines OS are all Windows 7 Ultimate SP1, Chinese native. For that, I developed using language resource features, but I repeat, it works fine on other machines. Just on some laptops it has the problem.

    5 & 6. I am not skilled, but not a first day beginner, then it is the first method I have used to look for the code line where the issue rises: I put messages like you suggest, and the result is that Step1 is shown, Step 3 is not!

    If I move the instruction  bIsBatTest = true above or below, together the messages, the result is the same: Step 1 shown then stop.

    7. Yes, it could be a way to better investigate the issue, but it will take a long time to install VS etc. To be honest, I have been hoping that someone can help without to do this .... :)

    8. the sw compiled just for x86 has the same error. The CPU is Intel(R) Core(TM) i5-4210M CPU @ 2.60GHz  2.60 GHz. RAM is 16.0 GB (15.7 GB available)

    9. My pc, the developing system, has a lot of SW installed, the target pc has only essential SWs and for testing I have also disabled any antivirus, antiware and similar.

    I hope all this can give you a more accurate frame to suggest me the root cause and so I to pass it. Otherwise I'm afraid that the only way to see more is to perform the step 7.

    Let me know, if you will be able .....

    Maurizio

    Tuesday, October 23, 2018 3:18 AM
  • I hope all this can give you a more accurate frame to suggest me the root cause and so I to pass it. Otherwise I'm afraid that the only way to see more is to perform the step 7.

    Let me know, if you will be able .....

    Maurizio

    Yes thank you for answering all that.

    If you can run the source on the problem system, put a break point on the line  bIsBatTest = false and single step exectution and see where it goes. ie exectute the = false, single step exectution, where does the execution go next? Error handler? Some other winproc sub routine where you use the bIsBatTest variable? Where does it get set to true? And what happens when it is true?

    What it that variable bIsBatTest and how does it interfer? There has to be something happening. You know computers. They dont just run off on their own and crash there is always a reason they run off and crash first.

    So you say that if you take out that line bIsBatTest = false then it works on the problem systems, correct? So it works while bIsBatTest = true but as soon as = false you get the error? Then it has to be executing somewhere else?

    Where is bIsBatTest declared? Is it public? Is it boolean?

    What is the next line cmdNEW.Text = My.Resources.sNEWBRD what does that do? Are you sure that is not the error?

    Oh, I guess you cant single step on the problem system. Hmmm.... You need to run the source on the problem system and see what is happening. Can you do that? Is it a customer or workmate or what? Run the source there and single step and see what it is doing.

    So yes I think all I have left is run the source on the problem system.

    Unless you can change the error handling somehow. Can you tell what line executes after the error? Unless the error actually occurs on the next line and on and on...

    Nope, I think you will need to execute the source on the problem computer, everything I can think of needs that?

    You don't use winproc or some other thing that can make the execution change and jump around? YOu don't use do events somewhere that has funny behavior?

    You don't have two things with the name bIsBatTest or it is not declared properly?

    I hate these type things.

    Oh, what if you change the language settings on the problem system does the error change?

    PS You don't use bIsBatTest in a different thread and get a cross threading err?

    You can use On Error Resume Next just temp to put a message on the line after the error and check the value or maybe see where it goes?

    PS this is the error?

        "cannot execute the program".

    That normally happens on start up? How do you know what line the error occurs on? Is that the exact error? Is there more error message? Show the whole thing.

    PS I guess its time to look at what is different on the problem system. Is it just the language that is different? Now I forgot. All the systems use the same language?


    PS Use Option Strict On and Option Implicit Off, fix any errors, try again.

    Tuesday, October 23, 2018 11:20 AM
  • The code in the rdBtn1.CheckedChanged event can(will) be fired before the form is loaded / shown.  This isn't a problem as long as it is taken into account.


    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."

    - from former MSDN User JohnWein

    SerialPort Info

    Multics - An OS ahead of its time.

    Tuesday, October 23, 2018 6:30 PM