question

VKSB-0116 avatar image
0 Votes"
VKSB-0116 asked VKSB-0116 answered

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

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



dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VKSB-0116 avatar image
0 Votes"
VKSB-0116 answered Viorel-1 edited

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

Try ByRef serr As String in the function definition.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VKSB-0116 avatar image
0 Votes"
VKSB-0116 answered

Hi Viorel,

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

Sorry.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.