How to send SMS with VB.NET? - vb.net

So I've been trying to send sms's with my VB.NET application but I had no luck.
I add the carrier and nothing.
#Region "Methods"
Private Sub frmMain_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' set up the carriers list - this is a fair list,
' you may wish to research the topic and add others,
' it took a while to generate this list...
cboCarrier.Items.Add("#itelemigcelular.com.br")
cboCarrier.Items.Add("#message.alltel.com")
cboCarrier.Items.Add("#message.pioneerenidcellular.com")
cboCarrier.Items.Add("#messaging.cellone-sf.com")
cboCarrier.Items.Add("#messaging.centurytel.net")
cboCarrier.Items.Add("#messaging.sprintpcs.com")
cboCarrier.Items.Add("#mobile.att.net")
cboCarrier.Items.Add("#mobile.cell1se.com")
cboCarrier.Items.Add("#mobile.celloneusa.com")
cboCarrier.Items.Add("#mobile.dobson.net")
cboCarrier.Items.Add("#mobile.mycingular.com")
cboCarrier.Items.Add("#mobile.mycingular.net")
cboCarrier.Items.Add("#mobile.surewest.com")
cboCarrier.Items.Add("#msg.acsalaska.com")
cboCarrier.Items.Add("#msg.clearnet.com")
cboCarrier.Items.Add("#msg.mactel.com")
cboCarrier.Items.Add("#msg.myvzw.com")
cboCarrier.Items.Add("#msg.telus.com")
cboCarrier.Items.Add("#mycellular.com")
cboCarrier.Items.Add("#mycingular.com")
cboCarrier.Items.Add("#mycingular.net")
cboCarrier.Items.Add("#mycingular.textmsg.com")
cboCarrier.Items.Add("#o2.net.br")
cboCarrier.Items.Add("#ondefor.com")
cboCarrier.Items.Add("#pcs.rogers.com")
cboCarrier.Items.Add("#personal-net.com.ar")
cboCarrier.Items.Add("#personal.net.py")
cboCarrier.Items.Add("#portafree.com")
cboCarrier.Items.Add("#qwest.com")
cboCarrier.Items.Add("#qwestmp.com")
cboCarrier.Items.Add("#sbcemail.com")
cboCarrier.Items.Add("#sms.bluecell.com")
cboCarrier.Items.Add("#sms.cwjamaica.com")
cboCarrier.Items.Add("#sms.edgewireless.com")
cboCarrier.Items.Add("#sms.hickorytech.com")
cboCarrier.Items.Add("#sms.net.nz")
cboCarrier.Items.Add("#sms.pscel.com")
cboCarrier.Items.Add("#smsc.vzpacifica.net")
cboCarrier.Items.Add("#speedmemo.com")
cboCarrier.Items.Add("#suncom1.com")
cboCarrier.Items.Add("#sungram.com")
cboCarrier.Items.Add("#telesurf.com.py")
cboCarrier.Items.Add("#teletexto.rcp.net.pe")
cboCarrier.Items.Add("#text.houstoncellular.net")
cboCarrier.Items.Add("#text.telus.com")
cboCarrier.Items.Add("#timnet.com")
cboCarrier.Items.Add("#timnet.com.br")
cboCarrier.Items.Add("#tms.suncom.com")
cboCarrier.Items.Add("#tmomail.net")
cboCarrier.Items.Add("#tsttmobile.co.tt")
cboCarrier.Items.Add("#txt.bellmobility.ca")
cboCarrier.Items.Add("#typetalk.ruralcellular.com")
cboCarrier.Items.Add("#unistar.unifon.com.ar")
cboCarrier.Items.Add("#uscc.textmsg.com")
cboCarrier.Items.Add("#voicestream.net")
cboCarrier.Items.Add("#vtext.com")
cboCarrier.Items.Add("#wireless.bellsouth.com")
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSend.Click
' Collect user input from the form and stow content into
' the objects member variables
mTo = Trim(txtPhoneNumber.Text) & _
Trim(cboCarrier.SelectedItem.ToString())
mFrom = Trim(txtSender.Text)
mSubject = Trim(txtSubject.Text)
mMailServer = Trim(txtMailServer.Text)
mMsg = Trim(txtMessage.Text)
' Within a try catch, format and send the message to
' the recipient. Catch and handle any errors.
Try
Dim message As New MailMessage(mFrom, mTo, mSubject, mMsg)
Dim mySmtpClient As New SmtpClient(mMailServer)
mySmtpClient.UseDefaultCredentials = True
mySmtpClient.Send(message)
MessageBox.Show("The mail message has been sent to " & _
message.To.ToString(), "Mail", _
MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Catch ex As FormatException
MessageBox.Show(ex.StackTrace, ex.Message, _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Catch ex As SmtpException
MessageBox.Show(ex.StackTrace, ex.Message, _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Catch ex As Exception
MessageBox.Show(ex.StackTrace, ex.Message, _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click
' Upon user’s request, close the application
Application.Exit()
End Sub
#End Region

If you are trying to SMS-enable a VB.NET application, I'd use this third party product:
Esendex
I used this in such a solution. The .NET SDK is devastatingly simple to understand and execute. The rates are reasonable and the support is excellent too.

Related

Auto update issue with drive C:/ in Vb.net

I've created a program with Vb.net that includes an "auto-update" feature. I made it using File A Sync and it seems to work fine, But that's only when I set up the program in any drive except the "C:/" drive, But when I set up the program on the "C:/" drive, The download doesn't start at all. I do not know why. I also tried searching for this issue online but couldn't find any help.
Imports System.IO
Imports System.ComponentModel
Public Class Updater
Dim client As New WebClient
Private Sub Updater_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Downloading_Bar.EditValue = 0
Speed_lb.Visible = True
Speed_lb.Text = " 0 kb/s"
Size_lb.Visible = True
Size_lb.Text = " 0 MB's / 0 MB's"
Try
AddHandler client.DownloadProgressChanged, AddressOf Client_ProgressChanged
AddHandler client.DownloadFileCompleted, AddressOf Client_DownloadCompleted
client.DownloadFileAsync(New Uri(Program_URL), Application.StartupPath & "\Changer NewVersion.exe")
Downloading_Bar.Properties.Step = 1
Downloading_Bar.Properties.PercentView = True
Downloading_Bar.Properties.Maximum = 100
Downloading_Bar.Properties.Minimum = 0
Catch ex As Exception
DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
Try
Speed_lb.Text = String.Format("{0} kb/s", (e.BytesReceived / 1024.0).ToString("00"))
Downloading_Bar.EditValue = e.ProgressPercentage.ToString()
Downloading_Bar.PerformStep()
Downloading_Bar.Update()
Size_lb.Text = String.Format("{0} MB's / {1} MB's", (e.BytesReceived / 1024.0 / 1024.0).ToString("0.00"), (e.TotalBytesToReceive / 1024.0 / 1024.0).ToString("0.00"))
Catch ex As Exception
DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
client.CancelAsync()
client.Dispose()
End Try
End Sub
Private Sub Client_DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
If Downloading_Bar.EditValue = 100 Then
Try
My.Computer.FileSystem.RenameFile(Application.StartupPath & "\Changer.exe", "Changer OlderVersion.exe")
My.Computer.FileSystem.RenameFile(Application.StartupPath & "\Changer NewVersion.exe", "Changer.exe")
Process.Start(Application.ExecutablePath)
Process.GetCurrentProcess.Kill()
Me.Dispose()
Catch ex As Exception
DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
Private Sub Updater_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
client.CancelAsync()
client.Dispose()
End Sub
End Class

How to print an access report protected by password?

I have an password-protected Access database, and I need to print a report in this database from my VB.Net code. How can I do it? I have this so far:
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAfdrukken.Click
Dim moApp As Access.Application
Dim acViewPreview As Access.AcView
Try
moApp = DirectCast(GetObject(, "Access.Application"), Access.Application)
Catch ex As Exception
If TypeName(moApp) = "Nothing" Then
moApp = DirectCast(CreateObject("Access.Application"), Access.Application)
Else
MessageBox.Show(ex.Message, "VB/Office Guru™ Access Demo", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Try
moApp.Visible = True
moApp.OpenCurrentDatabase("D:\media\urine (1).ACCDB")
moApp.RunCommand(Access.AcCommand.acCmdAppMaximize)
moApp.DoCmd.Maximize()
moApp.DoCmd.SetWarnings(False)
moApp.DoCmd.OpenReport("report1bw", acViewPreview)
moApp.CloseCurrentDatabase()
End Sub
Just use the password when opening the file.
moApp.OpenCurrentDatabase("D:\media\urine (1).ACCDB", bstrPassword := "somepassword")

vb.net login with sqlite

im trying to create a login form in vb.net with SQLite with this code
Imports System.Data.SQLite
Public Class frmLogin
Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
Dim table As DataTable = Nothing
Dim da As New SQLiteDataAdapter("Select * from user_tbl where username='" & txtuser.Text & "'and pass_id='" & txtpass.Text & "'", myconn)
Try
If txtuser.Text = "" And txtpass.Text = "" Then
MessageBox.Show("Please fill Username and Password", "Important", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtuser.Focus()
Else
da.Fill(table)
If table.Rows.Count > 0 Then
frmMain.Show()
Me.Close()
Else
MessageBox.Show("login not successful")
End If
da.Dispose()
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ConnectME()
End Sub
End Class
but i keep getting an error at line 26 "da.fill(table)"
Here is what the error says:
Here are two lines of your code:
Dim table As DataTable = Nothing
da.Fill(table)
You have no code in between that assigns an object to that table variable. Why exactly are you surprised that there's an issue here? If I told you to fill a bag and then handed you no bag, how exactly would you go about filling it? You couldn't, because you can't fill a bag that doesn't exist, yet you expect your app to be able to fill a DataTable that doesn't exist.

tcp connection with machine via ethernet using vb.net

I want to make a simple formapp using vb.net to send ASCII strings to a machine, that responds after every command. i.e., if i send "AA" it responds "123".
I can already open the connection cause if i check the connection with hyperterminal it says that the port is already being used. Yet, when i send commands i have no answer back.
I kinda adapted the template codes for server/client chat with tcp:
Imports System.Net.Sockets
Imports System.Threading
Dim Listener As New TcpListener(65535)
Dim Client As New TcpClient
Dim Message As String = "
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
If Listener.Pending = True Then
Message = ""
Client = Listener.AcceptTcpClient()
Dim Reader As New StreamReader(Client.GetStream())
While Reader.Peek > -1
Message = Message + Convert.ToChar(Reader.Read()).ToString
End While
RichTextBox1.ForeColor = Color.Black
RichTextBox1.Text += Message + vbCrLf
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSend.Click
If txtName.Text = "" Or cmbAddress.Text = "" Then
MessageBox.Show("All Fields must be Filled", _
"Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Try
Client = New TcpClient(cmbAddress.Text, 65535)
Dim Writer As New StreamWriter(Client.GetStream())
Writer.Write(txtName.Text & " Says: " & txtmessage.Text)
Writer.Flush()
RichTextBox1.Text += (txtName.Text & " Says: " & txtmessage.Text) + vbCrLf
txtmessage.Text = ""
Catch ex As Exception
Console.WriteLine(ex)
Dim Errorresult As String = ex.Message
MessageBox.Show(Errorresult & vbCrLf & vbCrLf & _
"Please Review Client Address", _
"Error Sending Message", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
is there a muuuuuuuch better way to do this? i read about .net.sockets but i coulndt get out of this.
and the manuals say nothing about how the machine operates. if it's a client, server, host.. can someone help me here? thank you !
Imports System.Net
Imports System.Net.Sockets
Imports System.Text.UTF7Encoding
Public Class Form1
Dim open As TcpListener
Dim server As TcpListener
Dim client, host As TcpClient
Dim dati, hdat As NetworkStream
Dim ip As String = Nothing
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ip = TextBox1.Text
client = New TcpClient
client.Connect(ip, 2101)
If client.Connected = True Then
dati = client.GetStream
MsgBox("Connected", MsgBoxStyle.Information)
Button1.Enabled = False
Timer1.Start()
Else
MsgBox("Error", MsgBoxStyle.Critical)
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If client.Available > 0 Then
Dim t(client.Available - 1) As Byte
dati.Read(t, 0, t.Length)
Dim testo As String = UTF7.GetString(t)
RichTextBox1.Text += vbCrLf & "server : " & testo & vbCrLf
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim t() As Byte = UTF7.GetBytes(TextBox2.Text & vbCrLf)
dati.Write(t, 0, t.Length)
RichTextBox1.Text += vbCrLf & TextBox2.Text & vbCrLf
End Sub
End Class

Row Scanning and Delay for Automatic Sms Sending in VB2012

I have a MS SQL Linked-Server (from Mysql) - generated Table TBL containing
*Index
*StdNo
*MobileNo
And I have a VB2012 code for SMS sending:
Private Sub cmdsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsend.Click
Try
If SerialPort1.IsOpen Then
With SerialPort1
.Write("AT" & vbCrLf)
.Write("AT+CMGF=1" & vbCrLf)
.Write("AT+CMGS=" & Chr(34) & TextBox1.Text & Chr(34) & vbCrLf)
.Write(RichTextBox1.Text & Chr(26))
End With
Else
MsgBox("Error on the port selected")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Where TextBox1.Text is the textbox where number is actually manually inputted
and RichTextBox1.Text is the message that will be sent.
What I wanted is to create a code that will automatically select each row of the table TBL for the MobileNo and then sends SMS. Since the VB code is not really for Bulk messaging, my idea is to create a loop that will scan each row, get each MobileNo, sends the message, then delay for a few second before the next row scan. I don't even know if it is possible. But I think it is, I just don't know how to come up with the loop and I don't even know how to create the connection between the database. Does anybody have any idea how to accomplish this?
may be you can use this code:
Private Sub cmdsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsend.Click
Try
If SerialPort1.IsOpen Then
With SerialPort1
.Write("AT" & vbCrLf)
.Write("AT+CMGF=1" & vbCrLf)
.Write("AT+CMGS=" & Chr(13)
.Write(TextBox1.Text)
.Write(Chr(26))
End With
Else
MsgBox("Error on the port selected")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub