user2649244
user2649244

Reputation: 111

Visual Basic Not all code paths return a value

In Visual Basic 2010, my program compiles without any problem. However, I get a warning "Not all code paths return a value" on function. Since our assignment requirement must submit without any error and warning so i need to solve these error.

Part of my sample code:

Dim i as integer = 0 
Dim currentChar as string = frmMyCompiler.textbox.text(i)

Function toNextWord() 
    i = i + 1 
    currentChar = frmMyCompiler.textbox.text(i)
end Function 

My function did not have any data type because it no need to return anything. Can VB use Void same as C++ ?? Anyone know how to overcome this problem?

Upvotes: 2

Views: 296

Answers (2)

andy
andy

Reputation: 6079

Functions should always a return a value. As your using Function toNextWord () it has no return value.

Difference between Method and Function

Upvotes: 1

Nenad
Nenad

Reputation: 26647

Use Sub toNextWord() to return void, instead of Function. Here you have documentation.

Upvotes: 3

Related Questions