Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
{\rtf1
\fs16
\ql
Star Code: STAR222YUUKXGF - Expires: 14/10/2010
\par
\par
AGASC_ID: 2098384
\par
\par
RA: 0h 38m 34.1s
\par
\par
DEC: +6° 33' 39.7"
\par
\par
MAG: 10.4
\page
\ql
Star Code: STAR2237T5U6PB - Expires: 14/10/2010
\par
\par
AGASC_ID: 393576
\par
\par
RA: 0h 27m 40.8s
\par
\par
DEC: +1° 13' 35.2"
\par
\par
MAG: 12.7
}
Private Sub GenerateStarCodes(ByVal NumCodes As Integer)
Dim RegionID As Integer = lstStarRegion.SelectedValue
Dim dt As DataTable
dt = GiftCode.GetStarCodesToCreate(NumCodes, RegionID)
Dim FileName, GiftCodeID As String
Dim dbconn, writeConn As SqlConnection
Dim writeComm As SqlCommand
Dim trans As SqlTransaction = Nothing
'Dim SQL As String
'Dim dbcomm As SqlCommand
'Dim dbread As SqlDataReader
Dim RTF As System.IO.StreamWriter
'Dim CodeLength As Integer
Dim Decl As String
'Dim Decl As String
'Open the connection to the database for the Stored Procedure
writeConn = New SqlConnection(ConfigurationManager.ConnectionStrings("Giftstring").ConnectionString)
writeConn.Open()
'Start the transaction
writeComm = New SqlCommand()
writeComm.Connection = writeConn
writeComm.CommandType = CommandType.StoredProcedure
writeComm.CommandText = "procCreateStarCode"
writeComm.Parameters.Add("@GiftCodeID", SqlDbType.Char, 16)
writeComm.Parameters.Add("@UserID", SqlDbType.Char, 10)
GiftCodeID = ""
Try
trans = writeConn.BeginTransaction
writeComm.Transaction = trans
Dim TypeID As String = Trim(lstProduct.SelectedValue)
'Create the RTF file
FileName = RTFLocation & TypeID & "-" & WebFunctions.FormatMySQLDate(Date.Now()) & "-" & Right("0" & Date.Now.Hour, 2) & "-" & Right("0" & Date.Now.Minute, 2) & "-" & Right("0" & Date.Now.Second, 2) & ".RTF"
RTF = New System.IO.StreamWriter(FileName)
'System.Text.Encoding.GetEncoding("windows-1252")
RTF.WriteLine("{\rtf1") ' open rtf
RTF.WriteLine("\fs16")
Dim DateString As String
DateString = WebFunctions.FormatMySQLDate(Date.Now.AddMonths(24))
dbconn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("GiftString").ConnectionString)
dbconn.Open()
If dt.Rows.Count > 0 Then
For i As Integer = 0 To NumCodes - 1
If i > 0 Then
RTF.WriteLine("\page")
End If
GiftCodeID = dt.Rows(i).Item("GiftCodeID")
RTF.WriteLine("\ql")
RTF.WriteLine(" Star Code: " & GiftCodeID & " - Expires: " & WebFunctions.FormatDateWithZeros(Date.Now().AddYears(2)))
RTF.WriteLine("\par")
RTF.WriteLine("\par")
RTF.WriteLine(" AGASC_ID: " & dt.Rows(i).Item("StarAGASCID"))
RTF.WriteLine("\par")
RTF.WriteLine("\par")
RTF.WriteLine(" RA: " & dt.Rows(i).Item("StarRA"))
RTF.WriteLine("\par")
RTF.WriteLine("\par")
Decl = dt.Rows(i).Item("StarDecl")
Decl = Decl.Replace(Chr(194), "")
'Dim c As String
'If c = "°" Then
'End If
'For x As Integer = 1 To Decl.Length
'c = Decl.Chars(x)
'Next
RTF.WriteLine(" DEC: " & Decl)
RTF.WriteLine("\par")
RTF.WriteLine("\par")
RTF.WriteLine(" MAG: " & dt.Rows(i).Item("StarMagnitude"))
'Add the code to the database
writeComm.Parameters("@GiftCodeID").Value = GiftCodeID
writeComm.Parameters("@UserID").Value = Session("BackendUserID")
writeComm.ExecuteNonQuery()
Next
End If
RTF.WriteLine("}")
RTF.Close()
'Email the document
Dim Files As New Collection
Files.Add(FileName)
WebFunctions.SendEmail("admin@gublic.com", EmailTo, lstProduct.SelectedItem.Text & " Codes", "", Files)
trans.Commit()
lblFeedback.Text = NumCodes & " codes for " & TypeID & " created and emailed to " & EmailTo
lblFeedback.Visible = True
Catch
If Not trans Is Nothing Then
trans.Rollback()
End If
If Not RTF Is Nothing Then
RTF.Close()
End If
lblFeedback.Text = "Codes not created. See the Application Administrator"
lblFeedback.Visible = True
End Try
End Sub
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
I tried the code below and it worked fine
Dim Decl As String = "+5° 41' 50.2"
Decl = Decl.Replace(Chr(194), "")
Is it throwing any exception?
Debug the code and check what is the value in Decl before and after you call Replace method