Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15072

VB2019 function returns single character of string instead of the entire string

$
0
0
Hi guys

I've got a bit of an odd problem. I'm designing a cross assembler console windows 10 desktop application which loads a source file and compiles it into object code and saves it.

The main module simply runs in a loop reading the source code in line-by-line, processing each one.

Mostly, this project is complete so I'm now in the process of adding extras. In this case a macro function.
I've defined a class called ClassMacros (original, I know :D) which contains various methods, one of which is called GetCurrentCmd which the main assember module calls.

Issue:
The method called is supplied with an integer index number to do a look up for a string, do some processing on that string, and then return it to the calling assembler module.
Unfortunately, the method keeps returning only the 1st character of the string when checked in the calling assembler module, but looks fine within method/function.

Checked :
The function statement contains the required 'As String' on the end
Displayed the string within the method (function) and it looks fine
Tried making the variable within the method (function) public - same issue occurs as when the variable is local
Removed the code from the method (function) and left one statement specifically setting the string value - same issue occurs
If I display the contents of the global variable which contains the string without passing it via the function Return statement (or using the function name = string) then the string is displayed fine in the calling assembler module
If I test the length of the returned string (from the calling module) it comes out as 1 and it's always the first character of whatever was passed by from the function.
I've tried to replicate this with a new project but been unable to.

In conclusion:
It seems that the function is behaving as if the returned string is either a string with a length of 1 or a Char type. I don't think it's doing a type conversion as I'm using 'Option Explicit On' and have not told vit to.

Any ideas? This has me a tad stumped :confused:.

Here's the class method/function with the guts removed and a test value added. 'sholder' is declared as a public variable as a test, but it makes no difference (and shouldn't):
Code:

    Public Function getCurrentCmd() As String

        sholder = "mike"
        Return sholder
    End Function


Here's the calling code in the main assembler module:
Code:

                          Console.WriteLine("Finding macro Command. Index: " & Macro.getIndex)

                            cmdline = Macro.getCurrentCmd(Macro.getIndex)
                            Macro.CurrentCmdIndex += 1
                            LineNumber -= 1
                            Console.WriteLine("Macro Run Command: " & cmdline)
                            Console.WriteLine(Len(cmdline))

When run, the above gives me:
Code:

Finding macro Command. Index: 0
Macro Run Command: m
1


[edit]

I forgot to show the cmdline variable declaration:
Code:

    Public CMDline As String
Code:

    Public sholder As String = ""
I've tried other variables with the same result. It all seems to be pointing to the class or function

Viewing all articles
Browse latest Browse all 15072

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>