11 Replies - 282 Views - Last Post: 26 December 2017 - 07:28 PM Rate Topic: -----

#1 JoeBobJr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Why are these if statements not working!

Posted 26 December 2017 - 12:58 PM

I can't for the life of me figure out why these checks are not working. I currently have two textboxes that are empty nothing in them at all and I'm never getting these messageboxes. What am I doing wrong?

    Private Sub chkStart_CheckedChanged(sender As Object, e As EventArgs) Handles chkStart.CheckedChanged
        If String.IsNullOrEmpty(Textbox1.Text) Then
            chkStart.Checked = False
            MessageBox.Show("Not a valid batch path!")
            Exit Sub
        End If
        If String.IsNullOrEmpty(Textbox2.Text) Then
            chkStart.Checked = False
            MessageBox.Show("Not a valid batch path!")
            Exit Sub
        End If
        If String.IsNullOrEmpty(Textbox3.Text) Then
            chkStart.Checked = False
            MessageBox.Show(txtFolderPath1.Text + vbNewLine + "Not a valid path!")
            Exit Sub
        End If
        If String.IsNullOrEmpty(Textbox4.Text) Then
            chkStart.Checked = False
            MessageBox.Show(txtFolderPath2.Text + vbNewLine + "Not a valid path!")
            Exit Sub
        End If
    End Sub




If any of these Textboxes are empty I want it to stop the rest of the code and display an error message. I have this code under a c

I have tried = "", = String.Empty, and I've also tried Textbox1.Text.Length > 0 and none of these are working for me.

Is This A Good Question/Topic? 0
  • +

Replies To: Why are these if statements not working!

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14244
  • View blog
  • Posts: 57,145
  • Joined: 12-June 08

Re: Why are these if statements not working!

Posted 26 December 2017 - 01:12 PM

You are certain the event is firing? Have you put a breakpoint in there to see?
Was This Post Helpful? 0
  • +
  • -

#3 JoeBobJr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: Why are these if statements not working!

Posted 26 December 2017 - 01:30 PM

View Postmodi123_1, on 26 December 2017 - 01:12 PM, said:

You are certain the event is firing? Have you put a breakpoint in there to see?


Yes because the next part of the code after those checks I have it change the text on the checkbox to "Stop" and have it start a timer and the timer starts and the text changes so its reaching the code after the if statements.
Was This Post Helpful? 0
  • +
  • -

#4 JoeBobJr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: Why are these if statements not working!

Posted 26 December 2017 - 01:35 PM

I have this code right after the code I posted which is all part of that checkchanged event

        If chkStart.Checked Then
            chkAutoStart.Enabled = True
            tmrStart.Start()
            chkStart.Text = "Stop"
            status.Text = "Started..."
            chkStart.ForeColor = System.Drawing.Color.OrangeRed
        Else
            chkStart.Checked = False
            chkStart.Text = "Start"
            tmrStart.Stop()
            chkStart.ForeColor = System.Drawing.Color.Aqua
            chkAutoStart.Checked = False
            chkAutoStart.Enabled = False
            status.Text = "stopped..."
        End If


Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14244
  • View blog
  • Posts: 57,145
  • Joined: 12-June 08

Re: Why are these if statements not working!

Posted 26 December 2017 - 02:17 PM

I am not follow. The code you showed was a complete event function. There's no stop, or what not in there. So you are not using Debugging and breakpoints to see if the event actually fires?
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • Unprocessable Entity
  • member icon

Reputation: 6578
  • View blog
  • Posts: 26,724
  • Joined: 12-December 12

Re: Why are these if statements not working!

Posted 26 December 2017 - 02:44 PM

I cannot follow your set-up, it seems an odd arrangement. It doesn't help that you are changing the Checked value inside the CheckChanged event, possibly more than once, probably firing the event again.

As suggested, debugging should reveal what is happening.

(You should rename your textboxes.)
Was This Post Helpful? 0
  • +
  • -

#7 JoeBobJr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: Why are these if statements not working!

Posted 26 December 2017 - 05:33 PM

View Postmodi123_1, on 26 December 2017 - 02:17 PM, said:

I am not follow. The code you showed was a complete event function. There's no stop, or what not in there. So you are not using Debugging and breakpoints to see if the event actually fires?


I'm not very good with coding as you can see. I'm not even sure how to put a break in the code and see if its firing. Can you give me an example?
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14244
  • View blog
  • Posts: 57,145
  • Joined: 12-June 08

Re: Why are these if statements not working!

Posted 26 December 2017 - 05:35 PM

Check that link. It outlines what to do.
Was This Post Helpful? 0
  • +
  • -

#9 JoeBobJr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: Why are these if statements not working!

Posted 26 December 2017 - 05:43 PM

An explanation of what I am doing would be good but there are honestly 450 lines of code in this app I'm working on so its pretty hard for me to post it all here.

I'm making an app that monitors my CPU and GPU miner for crypto mining. I have a bunch of timers that do different things. One checks hashrates of my miner using the miner APIs, one checks the processes to see if the miners are there and if not will auto run the miner in case it closes for any reason while I am away, and another timer that minimizes the cmd windows automatically.

The form contains 4 textboxes a textbox for the folder path of CPU miner, another for path of GPU miners, and the other two textboxes are the name of the batch file used to start the miner.

The autostart check box that this code is for starts all these timers and gets things moving. Each timer has an if statement checking to see if this checkbox is checked before it does what it needs to do.

Each textbox also has an openfiledialog or folderbrowserdialog on event click so I can choose the path to the miners. I just need some checks in place if some how the textboxes are not filled out when the checkbox is checked that it will give an error and uncheck the box so the timers don't start. Hopefully this all makes sense.

I've tried moving these if statements to check the textboxes in the timer that contains the process checker so if the boxes are empty it will give the error but even in that location its not working.
Was This Post Helpful? 0
  • +
  • -

#10 JoeBobJr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: Why are these if statements not working!

Posted 26 December 2017 - 06:05 PM

View Postmodi123_1, on 26 December 2017 - 05:35 PM, said:

Check that link. It outlines what to do.


It's saying...

The breakpoint will not currently be hit. No symbols have been loaded for this document.

I have no idea what that means.
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14244
  • View blog
  • Posts: 57,145
  • Joined: 12-June 08

Re: Why are these if statements not working!

Posted 26 December 2017 - 06:31 PM

Ambitious project.

Are you building in release mode? Should be a drop down at the top of by the menu. Swap that to debug.

Barring that..

Right click your project -> properties -> build.
Make sure 'Define DEBUG constant' and 'Define TRACE constant' are checked.

Same tab hit the 'advanced' button and change debug info to full.
Was This Post Helpful? 1
  • +
  • -

#12 JoeBobJr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: Why are these if statements not working!

Posted 26 December 2017 - 07:28 PM

View Postmodi123_1, on 26 December 2017 - 06:31 PM, said:

Ambitious project.

Are you building in release mode? Should be a drop down at the top of by the menu. Swap that to debug.

Barring that..

Right click your project -> properties -> build.
Make sure 'Define DEBUG constant' and 'Define TRACE constant' are checked.

Same tab hit the 'advanced' button and change debug info to full.


I figured it all out I needed to redo those if statements and move them into a different location. I've got it all working thank you for your help! Learned how to debug now!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1