I have the following code
Public Sub ConvertImage(ByVal Filename As String, _
ByVal DesiredFormat As System.Drawing.Imaging.ImageFormat, _
ByVal NewFilename As String)
' Takes a filename and saves the file in a new format
Try
Dim imgFile As System.Drawing.Image = _
System.Drawing.Image.FromFile(Filename)
imgFile.Save(NewFilename, DesiredFormat)
Catch ex As Exception
Throw ex
End Try
End Sub
Private Sub btnPrintVC40_Click(sender As System.Object, e As System.EventArgs) Handles btnPrintVC40.Click
Dim SigName As String
Dim SigNameNew As String
SigName = "SELECT Signature FROM vw_Report_VehicleCheckFTA WHERE VCID = " & CStr(lRiskAssessID)
SigNameNew = SigName.PadLeft(SigName.Length - 4)
ConvertImage(SigName, _
System.Drawing.Imaging.ImageFormat.Jpeg, _
SigNameNew & ".jpeg")
runReport("SELECT * FROM vw_Report_VehicleCheckFTA WHERE VCID = " & CStr(lRiskAssessID), "FTAVehicleCheck2.rpt")
End Sub
Basically what this should do is convert a png image to jpeg, then launch a crystal report. Instead I get the following exception:
I just can't for the life of me figure out why.
SigName = "SELECT Signature FROM vw_Report_VehicleCheckFTA WHERE VCID = " & CStr(lRiskAssessID) ' lRiskAssessID is 3772 I guess
SigNameNew = SigName.PadLeft(SigName.Length - 4) 'SignameNew will become "SELECT Signature FROM vw_Report_VehicleCheckFTA WHERE VCID = 3772", PadLeft will actually do nothing at all
ConvertImage(SigName, _
System.Drawing.Imaging.ImageFormat.Jpeg, _
SigNameNew & ".jpeg")
Convert Image is called with Filename "SELECT Signature FROM vw_Report_VehicleCheckFTA WHERE VCID = 3772" and I guess that's not the real filename.
You should take a look on how to get data from your database, you can't just throw some string in the air to get it ;)
Related
I have problem with this - I try to send broadcast SMS using AT Commands in my system. After that the SMS content will be stored in my database. My store content SMS function works well. I can store all my SMS content that I send, but the send function just sends message to my first data on my datagridview.
Please help me to deal with this - I posted my code below
Private Sub ButtonKirim_Click(sender As Object, e As EventArgs) Handles ButtonKirim.Click
Dim noPel As String
Dim isiPesan As String = ""
Dim tgl As Date = Now.Date
Dim strReplace(2) As String
Dim strIsi(2) As String
Dim tagBulan As String = "<bulan>"
Dim tagtagihan As String = "<tagihan>"
Dim tagLokasi As String = "<lokasi>"
Dim pesanKirim As String = ""
My.Settings.SettingPesan = RichTextBoxPesan.Text
My.Settings.Save()
'Label4.Text = isiPesan
For pelanggan As Integer = 0 To DataGridViewKirimPesan.RowCount - 1
'mengirim pesan/send message
noPel = DataGridViewKirimPesan.Rows(pelanggan).Cells(3).Value()
strReplace(0) = tagBulan
strReplace(1) = tagtagihan
strReplace(2) = tagLokasi
strIsi(0) = DataGridViewKirimPesan.Rows(pelanggan).Cells(4).Value
strIsi(1) = DataGridViewKirimPesan.Rows(pelanggan).Cells(5).Value
strIsi(2) = DataGridViewKirimPesan.Rows(pelanggan).Cells(6).Value
isiPesan = RichTextBoxPesan.Text
For i As Integer = LBound(strReplace) To UBound(strReplace)
isiPesan = isiPesan.Replace(strReplace(i), strIsi(i))
Next
SendMessage(noPel, isiPesan)
''menyimpan pesan keluar ke sms_terkirim/this query store my content SMS to table
Dim sqlSmsKeluar As String = "INSERT INTO sms_terkirim (`tgl_sms`,`id_pelanggan`, `isi_sms`) VALUES ( NOW()," & DataGridViewKirimPesan.Rows(pelanggan).Cells(0).Value & " , '" & isiPesan & "');"
cudMethod(sqlSmsKeluar)
MsgBox(sqlSmsKeluar)
'ProgressBarKirimPesan.Increment(1)
Next
'MsgBox("Pesan Sukses Terkirim")
' Catch ex As Exception
' MsgBox("Pesan Gagal Terkirim" + ex.Message)
'End Try
' End If
End Sub
and this code is AT Command to send message
Public Sub SendMessage(ByVal NomorPelanggan As String, ByVal IsiPesan As String)
If SerialModem.IsOpen() Then
With SerialModem
.Write("AT" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGS=" & Chr(34) & NomorPelanggan & Chr(34) & vbCrLf)
Threading.Thread.Sleep(100)
.Write(IsiPesan & vbCrLf & Chr(26))
Threading.Thread.Sleep(100)
End With
Else
MsgBox("Modem Belum Tersambung")
End If
End Sub
Hope someone can help with the above error.
I have the following code that worked fine with windows xp and a Kodak scanmate 1120
Private Sub BtnScan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnScan.Click
Dim img As WIA.ImageFile = Nothing
Dim wiaDialog As WIA.CommonDialog = New WIA.CommonDialog
Dim wiaScanner As WIA.Device
Dim root As String = "c:\myimages"
Dim IFileName As String = TxtInvoiceNo.Text
Dim WiaCommonDialog As New WIA.CommonDialog
If TxtInvoiceNo.Text = "" Then
'FrmPicDisplay.Show()
MsgBox("Please enter a valid Invoice No." & vbNewLine _
& "Then press scan button to continue.")
TxtInvoiceNo.Select()
ElseIf My.Computer.FileSystem.FileExists(root & IFileName & ".bmp") Then
MsgBox("This filename already exists," & vbNewLine _
& "Please enter a different filename")
TxtInvoiceNo.Text = ""
Else
Ino = TxtInvoiceNo.Text
wiaScanner = wiaDialog.ShowSelectDevice
With wiaScanner.Items(1)
.Properties("6146").Value = 4 '4 is Black-white,gray is 2, color 1 (Color Intent)
.Properties("6147").Value = 200 'dots per inch/horizontal
.Properties("6148").Value = 200 'dots per inch/vertical
.Transfer(wiaFormatTIFF) '("{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}") 'BMP format - This prompts the scan
End With
img = wiaScanner
Dim Item As WIA.Item = TryCast(wiaScanner.Items(1), WIA.Item)
Dim imageBytes As [Byte]() = DirectCast(img.FileData.BinaryData, Byte())
Dim ms As New MemoryStream(imageBytes)
Dim image_1 As Image = Image.FromStream(ms)
img.SaveFile("c:\myimages" & TxtInvoiceNo.Text & ".bmp")
I had to change the pc to windows seven and now the program doesn't work and gives me the above error at the line
img = wiaScanner
From what I have found by searching it sounds like a com exception but I don't really understand where to start looking so any help would be very much appreciated.
Thanks
Gareth
I'm working on an WindowsPhone 8 app that stores and reads it's data from its IsolatedStorage.
I'm using Visual Basic.NET and LINQ to XML.
There's no problem with loading/saving the data, but I've got a serious issue with replacing an XElement with [***XElementListName*].FirstOrDefault().ReplaceWith([NewXElementName])**.
It throws an System.AccessViolationException, but only if it's supposed to find and replace the data bound to the FIRST item in a LongListSelector, also the first of that element in the XML file. Editing any other item works fine thou.
Here's the code from the routine that is supposed to replace the data.
Dim Accounts = From el In XMLData.<accounts>.<account> Where _
el.Attribute("title").Value = oiTitle And _
el.Attribute("uname").Value = oiName And _
el.Attribute("pass").Value = oiPass And _
el.Attribute("site").Value = oiSite And _
el.Attribute("description").Value = oiDesc _
Select el
Dim acc As XElement = Accounts.FirstOrDefault()
If acc.Equals(Nothing) Then
MessageBox.Show("Error while saving edited account. Account not found.", "Account not found", MessageBoxButton.OK)
Exit Sub
End If
Dim tmpstr As String = acc.Attribute("title").Value + _
acc.Attribute("uname").Value + _
acc.Attribute("pass").Value + _
acc.Attribute("site").Value + _
acc.Attribute("description").Value
'Does this during debug to confirm that the replace is performed on the correct item.
MessageBox.Show(tmpstr, "Info about first item", MessageBoxButton.OK)
acc.Attribute("title").SetValue(NewInfo.Title)
acc.Attribute("uname").SetValue(NewInfo.Username)
acc.Attribute("pass").SetValue(NewInfo.Password)
acc.Attribute("site").SetValue(NewInfo.Site)
acc.Attribute("description").SetValue(NewInfo.Description)
' This code throws the exception when performing on the first item from the LongListSelector
Accounts.FirstOrDefault().ReplaceWith(acc)
I've searched and tried to figure it out by looking at the LINQ to XML documentation, but it lacks usable examples. Also checked this: How can I update/replace an element of an XElement from a string?
So, does anyone sit on any knowledge I could use to solve this?
If there's some code you'd like to see, just tell me, it's pretty ugly though.
EDIT: Omitted the Accounts.FirstOrDefault().ReplaceWith(acc) line, and it works just fine. Saves everything as it should. Also rewrote some code, here's the new one, and all the related code in that sub.
Public Sub EditAccount(ByVal OldInfo As AccountViewModel, ByVal NewInfo As AccountViewModel)
Dim IsStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
Dim File As New IsolatedStorageFileStream("Data.xml", FileMode.Open, IsStore)
Dim XMLData As XElement = XElement.Load(File)
Dim oiTitle As String = OldInfo.Title
Dim oiName As String = OldInfo.Username
Dim oiPass As String = OldInfo.Password
Dim oiSite As String = OldInfo.Site
Dim oiDesc As String = OldInfo.Description
Try
Dim Accounts = From e In XMLData.<accounts>.<account> Where ( _
e.Attribute("title").Value = oiTitle And _
e.Attribute("uname").Value = oiName And _
e.Attribute("pass").Value = oiPass And _
e.Attribute("site").Value = oiSite And _
e.Attribute("description").Value = oiDesc)
Select e Take 1
Dim Account As XElement = Accounts.FirstOrDefault()
If Account.Equals(Nothing) Then
MessageBox.Show("Error while saving edited account. Account not found.", "Account not found", MessageBoxButton.OK)
Exit Sub
End If
Dim tmpstr As String = Account.Attribute("title").Value + _
Account.Attribute("uname").Value + _
Account.Attribute("pass").Value + _
Account.Attribute("site").Value + _
Account.Attribute("description").Value
'MessageBox.Show(tmpstr, "Info about first item", MessageBoxButton.OK)
Account.Attribute("title").SetValue(NewInfo.Title)
Account.Attribute("uname").SetValue(NewInfo.Username)
Account.Attribute("pass").SetValue(NewInfo.Password)
Account.Attribute("site").SetValue(NewInfo.Site)
Account.Attribute("description").SetValue(NewInfo.Description)
File.Close()
IsStore.DeleteFile("Data.xml")
File = New IsolatedStorageFileStream("Data.xml", FileMode.Create, IsStore)
XMLData.Save(File)
File.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Me.LoadData()
End Sub
Omitted the Accounts.FirstOrDefault().ReplaceWith(acc) line, and it works just fine. Saves everything as it should. Also rewrote some code, here's the new one, and all the related code in that sub.
Public Sub EditAccount(ByVal OldInfo As AccountViewModel, ByVal NewInfo As AccountViewModel)
Dim IsStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
Dim File As New IsolatedStorageFileStream("Data.xml", FileMode.Open, IsStore)
Dim XMLData As XElement = XElement.Load(File)
Dim oiTitle As String = OldInfo.Title
Dim oiName As String = OldInfo.Username
Dim oiPass As String = OldInfo.Password
Dim oiSite As String = OldInfo.Site
Dim oiDesc As String = OldInfo.Description
Try
Dim Accounts = From e In XMLData.<accounts>.<account> Where ( _
e.Attribute("title").Value = oiTitle And _
e.Attribute("uname").Value = oiName And _
e.Attribute("pass").Value = oiPass And _
e.Attribute("site").Value = oiSite And _
e.Attribute("description").Value = oiDesc)
Select e Take 1
Dim Account As XElement = Accounts.FirstOrDefault()
If Account.Equals(Nothing) Then
MessageBox.Show("Error while saving edited account. Account not found.", "Account not found", MessageBoxButton.OK)
Exit Sub
End If
Dim tmpstr As String = Account.Attribute("title").Value + _
Account.Attribute("uname").Value + _
Account.Attribute("pass").Value + _
Account.Attribute("site").Value + _
Account.Attribute("description").Value
'MessageBox.Show(tmpstr, "Info about first item", MessageBoxButton.OK)
Account.Attribute("title").SetValue(NewInfo.Title)
Account.Attribute("uname").SetValue(NewInfo.Username)
Account.Attribute("pass").SetValue(NewInfo.Password)
Account.Attribute("site").SetValue(NewInfo.Site)
Account.Attribute("description").SetValue(NewInfo.Description)
File.Close()
IsStore.DeleteFile("Data.xml")
File = New IsolatedStorageFileStream("Data.xml", FileMode.Create, IsStore)
XMLData.Save(File)
File.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Me.LoadData()
End Sub
Cutting to the chase:
Function Create(ByVal network, ByVal location, ByVal type, ByVal requirement1, ByVal requirement2, ByVal requirement3, ByVal name)
Dim net As String = network
Dim loc As String = location
Dim typ As String = type
Dim nam As String = name
Dim req1 As String = requirement1
Dim req2 As String = requirement2
Dim req3 As String = requirement3
Dim Mission As New System.IO.StreamWriter("C:\" & nam & ".txt")
Mission.WriteLine("Name: " & net)
Mission.WriteLine("Network: " & net)
Mission.WriteLine("Location: " & loc)
Mission.WriteLine("Type: " & typ)
Mission.WriteLine("Requirement: " & req1)
Mission.WriteLine("Requirement: " & req2)
Mission.WriteLine("Requirement: " & req3)
Mission.Close()
Console.WriteLine("Written")
System.Threading.Thread.Sleep(3000)
End Function
No errors appear, but neither does the file in the filepath. I have it all declared when I call the function, so I know that its not the problem.
Help? :)
Sub Create(ByVal network As String, ByVal location As String,
ByVal type As String, ByVal requirement1 As String,
ByVal requirement2 As String, ByVal requirement3 As String,
ByVal name As String)
Dim net As String = network
Dim loc As String = location
Dim typ As String = type
Dim nam As String = name
Dim req1 As String = requirement1
Dim req2 As String = requirement2
Dim req3 As String = requirement3
If Not nam.EndsWith(".txt") Then
nam &= ".txt"
End If
Dim Mission As New System.IO.StreamWriter(Path.Combine(
System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Desktop), nam))
Mission.WriteLine("Name: " & net)
Mission.WriteLine("Network: " & net)
Mission.WriteLine("Location: " & loc)
Mission.WriteLine("Type: " & typ)
Mission.WriteLine("Requirement: " & req1)
Mission.WriteLine("Requirement: " & req2)
Mission.WriteLine("Requirement: " & req3)
Mission.Close()
Console.WriteLine("Written")
'System.Threading.Thread.Sleep(3000)
End Sub
first of all pal, you were passing the parameters as objects!!, second you dont have permission to save to c root directory unless you have administrator privilege, third the threading part at the end is completely useless, its blocking the UI and don't add up to any benefit.
at last but not least.
good luck
i upgrade my project to vb.net by using visual basic. i get a error when run the crystal report.
Call ReportConnection(CInspAuditList, "A")
CInspAuditList.ReportFileName = My.Application.Info.DirectoryPath & "\A.rpt"
Call SubReportConnection(CInspAuditList, "A")
CInspAuditList.set_ParameterFields(0, temp1)
CInspAuditList.set_ParameterFields(1, temp2)
CInspAuditList.set_ParameterFields(2, temp3)
CInspAuditList.set_ParameterFields(3, temp4)
CInspAuditList.Action = 1
my connection is
Public Function ReportConnection(ByRef CrystalReport1 As Object, ByRef dsnname As String) As Boolean
Try
CrystalReport1.Connect = "dsn=" & dsnname & ";UID=" & gstrID & ";PWD=" & gstrPassword & ";DSQ="
Catch ex As Exception
MsgBox(ex.ToString)
End
End Try
End Function
Public Function SubReportConnection(ByRef CrystalReport1 As Object, ByRef dsnname As String) As Object
Dim NReport As Short
With CrystalReport1
NReport = .GetNSubreports
Do While NReport > 0
.SubreportToChange = .GetNthSubreportName(NReport - 1)
.Connect = "dsn=" & dsnname & ";UID=" & gstrID & ";PWD=" & gstrPassword & ";DSQ="
.SubreportToChange = ""
NReport = NReport - 1
Loop
End With
End Function
i get error Exception from HRESULT: 0x800A501B at CInspAuditList.Action = 1
may i know how to fix the error???