variable length gets cut off

teel73

Registered User.
Local time
Yesterday, 16:19
Joined
Jun 26, 2007
Messages
205
Hi,

I have a public string variable that I pass a string to from a function. The string is not a fixed lenght. When I try to use the value stored from the public variable in another function, it chops the length of the string off. How can I pass this variable with the fixed length? The length of the string will be different each time. Below is what I have:

Here is my function where I set the public variables (strHypInfo)

Code:
Public strHypInfo as string
 
Function getHypelink()
 
Dim frm As Form
Dim rst As Recordset
Dim totRec As Long
Dim strBookmark As String
Dim strTitle, strAdd, strNews As Variant

Set frm = Form_frmDailyEvent_NewsHyperlinks
Set rst = frm.RecordsetClone
 
strHypInfo = ""
rst.MoveFirst

Do
    strTitle = rst!hyperlink_title
    strAdd = rst!hyperlink_address
    strNews = rst!news_details
    If strHypInfo = "" Then
        strHypInfo = "<font size = 2><a href='http://" & strAdd & "/'>" & strTitle & "</a><br>" & strNews
    Else
        strHypInfo = strHypInfo & "<br><br><font size = 2><a href='http://" & strAdd & "/'>" & strTitle & "</a><br>" & strNews
    End If
    rst.MoveNext
Loop Until rst.EOF = True
'
Debug.Print strHypInfo
 
End Function

The above code runs fine .. when I debug & print the string it returns the entire string ...

In my next function, I simply want a message box to return the value stored in the public variable strHypInfo. Below is my code:

Code:
Dim mystr As String
 
call getHypelink
 
msgbox strHypInfo

when I run the above function the intial string is cut off after so many characters.

Could someone assist me with this?
 
This is a shot in the dark, but try adding

DoEvents

after the call and before the message box. It could be that the function is still running when the message box fires.
 
The only salient difference that I see if the methods of displaying the text.
Why Print one out to the Immediate Window and then the other a Message Box (which has an inherent limitation of its width and number of rows it can display).

What are the two sets of results actually showing? Presumably quite a few rows of formatted HTML text?
Debug.Print both lots. Inconsistent debugging is debugging made more difficult. :-)

i.e. I'm saying - are you sure there's actually a problem at all? :-s

Cheers.
 
Good point Leigh. I hadn't considered that.
 
Hi Paul

My first rule of debugging - eliminate the discrepencies.
Eventually you get to Sherlock Holmes old axiom (often repeated in modern media - in shows such as CSI).
"When you have eliminated the impossible, whatever remains, however improbable, must be the truth"
I find that hard to argue with. :-)
 
Hello all and thank you for your replies. First, I am only doing a debug.print to check if my code is giving me the correct string. Second, it is a HTML string that I'm creating to provide to another function that uses HTML to format an Outlook email. Initially, the code works but it cuts off the entire string when I use the public variable in another function. Hopefully that explains what I'm trying to accomplish. Basically function (A) sets up my variable: myVar = "long HTML string", next funtion (B) wants to use myVar but what myVar returns when I try to use it is: "long HTML".
 
I understand the scenario you're decribing.
But we'd really need more to go on than that.
For example, the details of the two functions. i.e. how the second one uses the same variable as the first - and exactly how you've determined that it is truncated (where is that tested and what is the exact result)?

Cheers
 
This is a shot in the dark, but try adding

DoEvents

after the call and before the message box. It could be that the function is still running when the message box fires.


Hi ,, I tried the DoEvents to no avail .. its still chopping off the string. I don't understand why.
 
Message boxes are limited to 255 characters. If the string is longer than this it will cut off.
 
Hi Bob. 1024 ish characters but yes - it's limited.
Though it seems the implication is that it's not down to this testing methodology.
We'll see.
 
Yep, but it is a strange number - I would have thought 1024 would have been the number.
 
print your text debug.print in several places in the function and see where it get cut
if it get cut at the beginnig of function it must be cut in other place
 

Users who are viewing this thread

Back
Top Bottom