IF Without End IF in VBA [duplicate] - vba

This question already has answers here:
IF statements in VBA
(5 answers)
Closed 7 years ago.
see the code below.
IF Weight=0 Then CallFunction
IF Weight=100 Then
Heavy=True
Else
Heavy= False
End If
How is the program working when I have not ended a if statement?

its VBA's functionality to end up if statements in a single line..

If Weight is equal to zero, then CallFunction is executed (if Weight is not equal to zero, a CallFunction is not executed), then the code is going to another if statement. That's all! Debug the program to find out ;)

Related

Why is Visio VBA Exponentiation not working? [duplicate]

This question already has answers here:
VBA power operator (^) not working as expected in 64-bit VBA [duplicate]
(2 answers)
Closed 2 years ago.
Today Visio VBA is behaving differently. debug.print 2^2 prints "2 2" and debug.print 5.5^2 gives an error message "Compile error: Expected expression" while debug.print (5.5)^2 gives 30.25.
I don't remember ever seeing this before in the past probably 15 years of VBA programming, I expected to get 4 and 30.25
Use 2 ^ 2. The space is important.

Fat fingered decimal entry VBA for excel [duplicate]

This question already has answers here:
Decimal TryParse in VBA
(2 answers)
Closed 4 years ago.
I made a simple vba application that allows a user to enter data into excel. The data that's being entered had to be >= 1.99 ohms and can be 3.00 or higher. Everything works great and it's been in use for over a year now. However, recently a user fat fingered a decimal point and didn't catch it until they entered the number. VBA didn't like that and errored out. The format they entered looked like so: '.2.34'. I can't seem to figure out how to avoid this. Any suggestions?
I've tried using:
If Res.value <> Format(Number, "#.##") Then
Msgbox ("blah blah")
Res.Value = ""
Exit Sub
End if
This blocks those entries, but it also blocks correct entries.
Maybe you could add Data Validation rules on the typical ranges. Try this: Data > Data Tools > Data Validation

EF odd nullreferenceException with the same code already used and working [duplicate]

This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 5 years ago.
Sorry to bother you on this, but I'm a little confused.
I have this code in a sub called in Page_Load
Dim db As dbVulcanoEntities
Dim intervento As Interventi
Dim idint As Integer
idint = Request.QueryString("idint")
intervento = db.Interventi.Where(Function(i) i.IDInt = idint).Single
It fails on last line (in debug I see that idint has value) and if I query the db I get 1 record.
Odd thing is that I used this exact same code in another page of the same project (more than once,actually) and it works with no problem...
I can't understand why it's not working here... hints!? Thank you
EDIT:
I tried to add a condition like this
If db.Interventi.Any(Function(i) i.IDInt = idint) Then
but it doesn't even pass it, so I guess it doesn't like the "i.IDInt = idint" part for some reason.
The code as posted will, indeed, produce a NullReferenceException as you are never assigning a value to the db local variable, so I am expecting it to be Nothing.

Out of stack space (Error 28) VBA [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am trying to convert an old Fortran program with a lot of nested goto statements to VBA but I am getting error mentioned in the title. The way I am converting is each statement, I made it a function and instead of goto then i call the function or statement, but apparently that's not a proper way of doing it. What else can I do? Thanks in advance.
If you cannot see where the endless loop is, try adding a public counter to all of the functions. If it exceeds a given value, stop the program. Then try to debug with F8 to see the endless loop. I mean something like this:
Option Explicit
Public counter As Long
Public Sub TestMe()
While True
FunctionSomething
Wend
End Sub
Public Function FunctionSomething()
counter = counter + 1
If counter > 100 Then Stop
End Function
Now if you run TestMe it would stop on the 100th iteration.

How to check a image byte array is empty in VB.Net? [duplicate]

This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 6 years ago.
Hello I need to check if a variable which loads a photo is empty. It's define as Byte(). IDE throwing error when I do this - If Photo.Length = 0 then. I really need your help. Thanks.
Perhaps you need to perform a null check on the array before you attempt to access any properties. You'll need to post more code if you want better help.
If Photo IsNot Nothing AndAlso Photo.Length > 0 Then
'Photo isn't empty
End If