|
I got the codes to send sms using VB and i came across these two sample codes.
Sending SMS using .NET[^]
http://www.daniweb.com/forums/post250164-19.html#[^]
I copied and paste the following codes in my Class Library file. i have bold the codes with problems.
Option Explicit On
Imports System
Imports System.Threading
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.IO.Ports
Public Class SMSCOMMS
Private WithEvents SMSPort As SerialPort
Private SMSThread As Thread
Private ReadThread As Thread
Shared _Continue As Boolean = False
Shared _ContSMS As Boolean = False
Private _Wait As Boolean = False
Shared _ReadPort As Boolean = False
Private WithEvents DBServer As Postgres " PROBLEM - type 'Postgres' is not defined "
Public Event Sending(ByVal Done As Boolean)
Public Event DataReceived(ByVal Message As String)
Public Sub New(ByRef COMMPORT As String)
SMSPort = New SerialPort
With SMSPort
.PortName = COMMPORT
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
DBServer = New Postgres() " PROBLEM - type 'Postgres' is not defined "
ReadThread = New Thread(AddressOf ReadPort)
End Sub
Public Function SendSMS(ByVal CellNumber As String, ByVal SMSMessage As String) As Boolean
Dim MyMessage As String = Nothing
'
'Check if Message Length <= 160
If SMSMessage.Length <= 160 Then
MyMessage = SMSMessage
Else
MyMessage = Mid(SMSMessage, 1, 160)
End If
'MsgBox("Sending " & MyMessage & " to " & CellNumber)
If IsOpen = True Then
SMSPort.WriteLine("AT+CMGS=" & CellNumber & vbCr)
_ContSMS = False
While _ContSMS = False
Application.DoEvents()
End While
SMSPort.WriteLine(MyMessage & vbCrLf & Chr(26))
_Continue = False
RaiseEvent Sending(False)
End If
End Function
Private Sub ReadPort()
Dim SerialIn As String = Nothing
Dim RXBuffer(SMSPort.ReadBufferSize) As Byte
Dim SMSMessage As String = Nothing
Dim Strpos As Integer = 0
Dim TmpStr As String = Nothing
While SMSPort.IsOpen = True
If (SMSPort.BytesToRead <> 0) And (SMSPort.IsOpen = True) Then
While SMSPort.BytesToRead <> 0
SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize) 'SMSPort.BytesToRead
SerialIn = SerialIn & System.Text.Encoding.ASCII.GetString(RXBuffer)
' Handle Internal Events
' For Received Characters
If SerialIn.Contains(">") = True Then
_ContSMS = True
End If
If SerialIn.Contains("+CMGS:") = True Then
_Continue = True
RaiseEvent Sending(True)
_Wait = False
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
RaiseEvent DataReceived(SerialIn)
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
End Sub
Public ReadOnly Property IsOpen() As Boolean
Get
If SMSPort.IsOpen = True Then
IsOpen = True
Else
IsOpen = False
End If
End Get
End Property
Public Sub Open()
If IsOpen = False Then
SMSPort.Open()
ReadThread.Start()
End If
End Sub
Public Sub Close()
If IsOpen = True Then
SMSPort.Close()
End If
End Sub
End Class
Next, i have also copied the following codes below into my windows form. I'm not sure if i've pasted the codes in the write place but that is wat i have done.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SMSEngine = New SMSCOMMS("COM1")
SMSEngine.Open()
SMSEngine.SendSMS("919888888888", "SMS Testing")
SMSEngine.Close()
End Sub
The problem i faced is that the SMSEngine was not declared. How do i solve this?
THANKS IN ADVANCE!!
|
|
|
|
|
If you took the time to try and understand the code instead of just Copy'N'Paste what you don't understand and expecting it to work, then you would realize that this code uses a Postgres database for something that probably has nothing to do with sending SMS messages. It looks like you can get rid of those two lines and not worry about them.
|
|
|
|
|
haha. Thanks for your help. I'm new to visual basics and started only a few days ago, so i dun really get what some of the codes are used for. Sorry. haha. I need to use these codes to do a project.
Am i doin things the right way? like where i placed the codes in my program? How do i define or declare the SMSEngine in the codes? thanks
|
|
|
|
|
gjx_junxian1989 wrote: Am i doin things the right way?
Copy'N'Paste coding? Hell No.
gjx_junxian1989 wrote: where i placed the codes in my program?
I have no idea hwere you placed any of this stuff in your app.
gjx_junxian1989 wrote: How do i define or declare the SMSEngine in the codes?
What SMS Engine? Your code snippet doesn't mention anything about an engine. Or are you saying that the code you posted IS the engine? If so, then your problems do not lie in knowing VB.NET, but the basic concepts of object oriented programming. These are design issues that I really can't walk you through in a forum post.
|
|
|
|
|
Hello,
We have a VB.Net program that uses GetObject() method. While executing the program, it gives the following exception.
"Unhandled Exception: System.Exception: Cannot create ActiveX component.
at Microsoft.VisualBasic.Interaction.GetObject(String PathName, String Class)"
The same program is executing successfully in our production environment but not in one of the development environment. We came to know that the program referring to STDOLE.DLL which is not there on the development machine where the program fails. Even if we copy the same dll on that machine, it is not working. How can we install Primary Interop Assemblies seperately? we do not want to install Visual studio.net.
Please let me know what are all the dlls required to use GETOBJECT() method in VB.Net program?
Thank you in advance,
Raheem MA 
|
|
|
|
|
Are you sure the ActiveX component is correctly registered? The error you get is not an error of the GetObject function but that your ActiveX component is not registered correctly.
Try to registed the component by executing 'regsvr32 x:\path\myactivex.dll'.
Tosch
|
|
|
|
|
Thank you for quick reply,
We do not have STDOLE.DLL on our machine. So it cannot be registered right? What is required to install on the machine to get this dll? once again reminding you we do not want to install Visual studio.Net.
Thank you,
Raheem MA
|
|
|
|
|
You have to make a setup project from the computer that VS.net is installed on. After that you have to run the setup installation file on the required machine.
Shay Noy
|
|
|
|
|
I think this answer is not related to my question.
I read somewhere that STDOLE.DLL comes with Visual Studio.Net. Are there any alternatives to get this DLL installed without Visual Studio.Net?
Thanks.
|
|
|
|
|
I would like to understand:
Does the program, written on the machine which VS.net is installed on, run succesfully?
If yes, you have to create a new setup project including all the required files (also STDOLE.dll) and then run it in the relevant computer.
Do I understood correctly what you need?
Shay Noy
|
|
|
|
|
yes, our program is a console application which is called from formscape reports. we have copied only exe of the program in the production and running successfully.
On the production system, we have primary Interop Assemblies folder at the following path:
C:\Program Files\Microsoft.NET\Primary Interop Assemblies
Following are the contents of the folder:
1. adodb.dll
2. Microsoft.mshtml.dll
3. Microsoft.stdformat.dll
4. msdatasrc.dll
5. MSDDSLMP.DLL
6. MSDDSP.DLL
7. stdole.dll - This is reffered in our program.
We could not find this folder on development machine. That may be the reason we are getting the exception saying 'Cannot create ActiveX .....".
How can we install these dlls ?
Please shed some light in this scenario.
Thank you in advance
Raheem MA
|
|
|
|
|
|
Is there a preprocessor macro to get the current function name or is it available from a particular global class? I know there is a preprocessor macro to get line numbers if you use them.
|
|
|
|
|
Try this:
Reflection.MethodBase.GetCurrentMethod.ToString
Shay Noy
|
|
|
|
|
Thanks; I think that will work for my VB .NET projects. Do you happen to know a method that will work in VB6 as well?
|
|
|
|
|
No, I don't. You can check in google
Shay Noy
|
|
|
|
|
2 questions.
Is it possible to fire data from an excel sheet into MWD form via a macro in excel?
and
How?
I have never used this database before, and it is a bit of a legacy thing that needs to be addressed.
I have tried googling, but can't find much that helps, if you know of a good site that too would be useful.
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
I haven't used Works for yonks and yonks, but from memory it deals with csv files reasonably well. You could fire the data to a *.csv file and open it in works.
I googled microsoft works csv and got a fair few hits about works to excel you might want to have a look yourself.
I also found two links to a couple of works libraries Libwpd and Libwps (below) that might be worth further digging?
Libwpd[^]
Libwps[^]
Hope this is of some help.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks Henry, I shall have a play with it in the morning.
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
Before you get out of bed, or wait till you're in the bathroom?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Probably at work, I am in bed as we speak!
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
Henry Minute wrote: Before you get out of bed, or wait till you're in the bathroom?
That has made me chuckle!
|
|
|
|
|
Liqz wrote: That has made me chuckle
Good.
It actually works on two levels, since the OP and I both utilize Mobile Broadband, so both scenarios are possible.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hello,
I want to write a programme. It's mantality is as same as Autoit. I have a windows form and when ı clicked to Button, ı want to send 1 or 2 or Ctrl+Alt+F2. My friend is playing a game and said me: can you do this? I said yes. Soooo... I use Sendkeys.send() as below:
--------Button1.Click-----------------------
SendKeys.Send(Chr(Keys.D1))
System.Threading.Thread.Sleep1000)
SendKeys.Send(Chr(Keys.D2))
I use it but it sent 1(but Text form of 1 - string) 
|
|
|
|
|
First, controlling another application using SendKeys is about the poorst method you can use. SendKeys send keystrokes to whichever window with the focus, without caring about which window has the focus! You could be sending keystroked to Notepad when you actually wanted Calculator. There is no way to guarantee that every keystroke you send is going to end up going to the correct window.
Next, why are you converting the Keys to Characters?? Just send the Keys valoue, not the converted Chr value.
ms_cdr wrote: I use it but it sent 1(but Text form of 1 - string)
I don't have the slightest clue what you're trying to say here. This doesn't make any sense at all.
|
|
|
|