vb.net - How to handle second condition in If Else statement -


how handle second condition in if else statement, if statement working second condition not working(elseif), there wrong condition declaration?

try             if val(textbox7.text.trim.split(".")(1)) >= 60                  textbox7.text = val(textbox7.text.trim.split(".")(0)) + 1 & "." & val(textbox7.text.trim.split(".")(1) - 60) & " " & format(now, "mm/dd/yyyy")                 textbox3.text = val(textbox3.text.trim.split(".")(0)) & "." & val(textbox3.text.trim.split(".")(1) - 60) & " " & format(now, "mm/dd/yyyy")              elseif val(textbox7.text.trim.split(".")(1)) >= 100                  textbox7.text = val(textbox7.text.trim.split(".")(0)) - 1 & "." & val(textbox7.text.trim.split(".")(1) - 45) & " " & format(now, "mm/dd/yyyy")                 textbox3.text = val(textbox3.text.trim.split(".")(0)) - 1 & "." & val(textbox3.text.trim.split(".")(1) - 45) & " " & format(now, "mm/dd/yyyy")               else                 textbox7.text = format(val(textbox6.text) + val(strings.left(time.text.trim, 5)), "##.00") & strings.right(time.text.trim, 11)                 textbox3.text = format(val(textbox6.text) + val(strings.left(time.text.trim, 5)), "##.00") - 1 & strings.right(time.text.trim, 11)                 'textbox3.text = format(val(textbox3.text.trim.split(".")(0) - 1) & "." & val(textbox3.text.trim.split(".")(1)) & " " & format(now, "mm/dd/yyyy"))             end if         catch             textbox7.text = format(val(textbox6.text) + val(strings.left(time.text.trim, 5)), "##.00") & strings.right(time.text.trim, 11)         end try  

what @james said + i'd suggest rewrite select case - should easier follow:

select case val(textbox7.text.trim.split(".")(1))   case >= 100     textbox7.text = val(textbox7.text.trim.split(".")(0)) - 1 & "." & val(textbox7.text.trim.split(".")(1) - 45) & " " & format(now, "mm/dd/yyyy")     textbox3.text = val(textbox3.text.trim.split(".")(0)) - 1 & "." & val(textbox3.text.trim.split(".")(1) - 45) & " " & format(now, "mm/dd/yyyy")   case >= 60     textbox7.text = val(textbox7.text.trim.split(".")(0)) + 1 & "." & val(textbox7.text.trim.split(".")(1) - 60) & " " & format(now, "mm/dd/yyyy")     textbox3.text = val(textbox3.text.trim.split(".")(0)) & "." & val(textbox3.text.trim.split(".")(1) - 60) & " " & format(now, "mm/dd/yyyy")   case else     textbox7.text = format(val(textbox6.text) + val(strings.left(time.text.trim, 5)), "##.00") & strings.right(time.text.trim, 11)     textbox3.text = format(val(textbox6.text) + val(strings.left(time.text.trim, 5)), "##.00") - 1 & strings.right(time.text.trim, 11) end select 

also several points of interest:

  • don't use val, use convert class instead, example, convert.toint32.
  • you can wrap textbox3.text.trim.split(".") function, , reuse.
  • you read date twice, it's better read date once before select, datevar.tostring("mm/dd/yyyy").
  • favour .net syntax instead of vb6. val, format, strings.left vb6. .net equivalents convert.*, tostring format string, , substring.
  • control naming - textbox3 , textbox7 don't mean anything. try come better name them.

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -