How to do a String Variable (must be able to hold 256 Bytes) if it is "Empty" to show message "Nothing"?

VKSB 236 Reputation points
2021-08-07T08:01:43.393+00:00

Hi Friends,

I am using a Function from "Swiss Ephemeris" (https://www.astro.com/swisseph/swephinfo_e.htm).

Public Declare Function swe_solcross_ut Lib "swedll32.dll" _
        Alias "_swe_solcross_ut@24" ( _
          ByVal x2cross As Double, _
          ByVal jd_ut As Double, _
          ByVal iflag As Int32, _
          ByVal serr As String _
        ) As Double ' serr must be able to hold 256 bytes

Dim Answer, Cross, JD As Double
Dim iflag As Integer
Dim serr As String = Space(256)

When this function is called, the "serr" is an Error message given by this function if there is any.

I want to display the Error message ("serr") if there is any, otherwise I want to display "No Error Message".

I tried the following but it fails.

 If serr = "" Then
            Console.WriteLine(" No Error Message: ")
        Else
            Console.WriteLine(" Error Message: " & serr)
        End If

Can you please help me on this.

Thanks

Developer technologies | VB
0 comments No comments
{count} votes

Accepted answer
  1. VKSB 236 Reputation points
    2021-08-08T12:01:03.57+00:00

    Hi RLWA32-6355,

    Thanks for the reply.

    No! Sorry your method too fails; it doesn't show "No Error Message" when swe_solcross_ut method does not write anything to the serr string (i.e.: when there is no error).

    Anyway, I solved this problem yesterday soon after replying to "Viorel".

    My code is:

      If serr < Space(256) Then  
                    Console.WriteLine(vbCrLf & " Error Message : Nothing ! " )
                Else
                    Console.WriteLine(vbCrLf & " Error Message: " & serr )
                End If
    
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2021-08-07T08:11:41.727+00:00

    Try ByRef serr As String in the function definition.

    0 comments No comments

  2. VKSB 236 Reputation points
    2021-08-07T10:31:23.217+00:00

    Hi Viorel,

    No! You didn't understand my question & You didn't answer my question.

    Sorry.

    0 comments No comments

  3. RLWA32 49,541 Reputation points
    2021-08-08T10:47:01.467+00:00

    Assuming that the _swe_solcross_ut method does not write anything to the serr string if successful then try this -

    If serr.Equals(Space(256)) Then
        Console.WriteLine("No Error Message")
    Else
        Console.WriteLine("Error Message : " & serr)
    End If
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.