Telnet (winsock) connection in VBA - class not registered - vba

I have GSM gateway that use telnet for sending/recivieng SMS. I'am making a small app in my ms-access for sending sms notifications for my clients. For that I need winsock connection from my client computer -> gsm gateway. It supposed to be easy :)
I can't establish an object. I'm receiving run-time error -2147221164(80040154) - Class not registered. Error is indicated in "Set winsock = ..." line. I have added reference MS Winsock Control 6.0 (SP6) - MSWINSCK.OCX. I have a feeling this is a problem with reference, but I don't have any idea how to correct it (code below is simplified) :( .
Option Explicit
Private WithEvents Winsock1 As Winsock
Sub Start_Telnet_Session()
Dim Data As String
Dim Winsock1
Set Winsock1 = New MSWinsockLib.Winsock
Winsock1.RemoteHost = "192.168.1.1"
Winsock1.RemotePort = "23"
Winsock1.connect
Do Until Winsock1.State = 7
DoEvents
If Winsock1.State = sckError Then
Exit Sub
End If
Loop
Winsock1.SendData "user" & vbCrLf
Winsock1.SendData "pass" & vbCrLf
Dim I As Integer
I = 5
While TelnetCommands <> ""
Winsock1.SendData "TelnetCommands" & vbCrLf
Winsock1.GetData Data
Data = VBA.Replace(Data, vbLf, "")
Data = VBA.Replace(Data, vbCr, vbNewLine)
MsgBox Data
I = I + 1
Wend
Winsock1.Close
End Sub

Related

"IF" code is not working inside for each?

so im learning to use socket and thread things in the networking software. so far, the software (which is not created by me) is able to chat in multiple group, but i'm tasked to allow user to code whisper feature. However, im stuck in the coding area, which im sure will work if the "if" function work inside "for each" function, anyhow here is my code mainly
Private clientCollection As New Hashtable()
Private usernameCollection As New Hashtable()
clientCollection.Add(clientID, CData)
usernameCollection.Add(clientID, username)
oh and before i forgot, the code above and below is on the server form page
on the client side, i write the code:
writer.write("PMG" & vbnewline & txtReceiverUsername & Message)
then next is the checking part on the server reading the message:
ElseIf message.Substring(0, 3) = "PMG" Then
'filter the message, check who to send to
Dim newMessage As String = message.Substring(3)
Dim messagearray As String() = newMessage.Split(vbNewLine)
Dim receiver As String = messagearray(1)
'0 = "", 1 = receiver, 2 = message
as i write before, clientcollection contain (clientID , connection data*) and usernamecollection contain (clientID, username). In my case, i only have the username data, and i need to trace it until the connection data on clientcollection hash table.
'find realid from usernamecollection, then loop clientcollection
Dim clientKey As String = 0
For Each de As DictionaryEntry In usernameCollection
'''''
'this if part Is Not working
If de.Value Is receiver Then
clientKey = de.Key
End If
'''''
Next de
'match objKey with clientcollection key
For Each dec As DictionaryEntry In clientCollection
If dec.Key = clientKey Then
Dim clients As ClientData = dec.Value
If clients.structSocket.Connected Then
clients.structWriter.Write("PMG" & messagearray(2))
End If
End If
Next dec
End If
so, how do i know that the if part is the wrong one? simply i tried these code before the "next de" code
For Each client As ClientData In clientCollection.Values
If client.structSocket.Connected Then
client.structWriter.Write("PMG" & "receiver:" & messagearray(1))
client.structWriter.Write("PMG" & "loop username: " & de.Value)
client.structWriter.Write("PMG" & "loop key: " & de.Key)
client.structWriter.Write("PMG" & "receiver key:" & clientKey)
End If
Next
the code allow me to check the de.key and de.value. they were correct, however the only thing that did not work is the code inside the "if" area.
Can anyone suggest other code maybe beside "if de.key = receiver"? I've also tried using the if de.key.equal(receiver) and it did not work too

VB Authenticate User In Outlook Web App

I currently have a mail system using Microsoft's exchange server (OWA). I am trying to authenticate a user and send an email using pure Visual Basic code.
I have been trying to use a library called Aspose, however; I have no idea if I'm on the right track. I can not get it to work and I am not sure (since this is a company mail server) whether it's the server or it's my code.
Currently I have,
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create instance of ExchangeClient class by giving credentials
Dim client As Aspose.Email.Exchange.ExchangeClient = New Aspose.Email.Exchange.ExchangeClient("https://MAILSERVER.com/username/", "username", "password", "https://MAILSERVER.com/")
' Create instance of type MailMessage
Dim msg As Aspose.Email.Mail.MailMessage = New Aspose.Email.Mail.MailMessage()
msg.From = "username#MAILSERVER.com"
msg.To = "receivingemail#gmail.com"
msg.Subject = "test"
msg.HtmlBody = "test"
' Send the message
Try
client.Send(msg)
Console.WriteLine("made it")
Catch ex As Exception
Console.WriteLine("failed")
End Try
End Sub
I have obviously changed the username, password, and server name fields to generic ones but with (what I think is the right credentials) the output is always failed.
Can anybody help me out please?
Here is what I use:
Public Shared Function SendEMail(MailMessage As System.Net.Mail.MailMessage) As String
ErrorMess = ""
' Default the from address, just in case is was left out.
If MailMessage.From.Address = "" Then
MailMessage.From = New Net.Mail.MailAddress("donotreply#MAILSERVER.com")
End If
' Check for at least one address
If MailMessage.To.Count = 0 AndAlso MailMessage.CC.Count = 0 AndAlso MailMessage.Bcc.Count = 0 Then
ErrorMess = "No Addresses Specified"
Return ErrorMess
End If
' Create a SMTP connedction to the exchange 2010 load balancer.
Dim SMTPClient As New System.Net.Mail.SmtpClient("MAILSERVER.com")
Try
Dim ValidUserCredential As New System.Net.NetworkCredential
ValidUserCredential.Domain = "MAILSERVER.com"
ValidUserCredential.UserName = My.Resources.EmailUserName
ValidUserCredential.Password = My.Resources.EmailPassword
SMTPClient.UseDefaultCredentials = False
SMTPClient.Credentials = ValidUserCredential
SMTPClient.Send(MailMessage)
Return "Mail Sent"
Catch ex As Exception
ErrorMess = ex.Message & " " & ex.InnerException.ToString
Return ErrorMess
End Try
End Function
The ExchangeClient class is used to connect to Exchange server using the WebDav protocol and is used with Exchange Server 2003 and 2007. For OWA, you need to use the IEWSClient interface as shown in the following sample code. It has an Office365 test account that you can use to send a test email (the test account is solely for testing purpose and is not property of Aspose. I just created it for assisting you in testing the functionality). Please try it and if you face any problem, you may share the porblem on Aspose.Email forum for further assistance.
' Create instance of IEWSClient class by giving credentials
Dim client As IEWSClient = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "UserTwo#ASE1984.onmicrosoft.com", "Aspose1234", "")
' Create instance of type MailMessage
Dim msg As New MailMessage()
msg.From = "UserTwo#ASE1984.onmicrosoft.com"
msg.[To] = "receiver#gmail.com"
msg.Subject = "Sending message from exchange server"
msg.IsBodyHtml = True
msg.HtmlBody = "<h3>sending message from exchange server</h3>"
' Send the message
client.Send(msg)
I work with Aspose as Developer evangelist.

SEND SMS from samsung galaxy win celphone using vb.net

How to send sms from your cellphone to any number using vb.net? I have searched over the internet including youtube but it seems that i could not find or cant figure out where to start. My CP cant event detected in the "phone and modem" in windows...
I have a perfect way to send SMS in visual basic, using AT-commands.
AT-commands:are instructed through which you can send and receive SMS messages, make calls from cell phone, and this is an example to Send a message:
Firstly:
Write this code in the top:
Imports System.IO.Ports
Imports System.IO
Secondly:
Write this code in the public class of form:
Dim SerialPort As New System.IO.Ports.SerialPort()
Dim CR As String
Thirdly:
Create a textBox(TextmsgTextBox) to write the text message, and TextBox2(MobileNumberTextBox) to enter the mobile number, and Button(SendBUT) to Send message.
And write this code in the button click event.
If SerialPort.IsOpen Then
SerialPort.Close()
End If
SerialPort.PortName = COM4
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf
Dim message As String
message = MsgRichTextBox.Text
SerialPort.Open()
If SerialPort.IsOpen() Then
SerialPort.Write("AT" & vbCrLf)
SerialPort.Write("AT+CMGF=1" & vbCrLf)
SerialPort.Write("AT+CMGS=" & Chr(34) & phoneNumBox.Text & Chr(34) & vbCrLf)
SerialPort.Write(message & Chr(26))
SentPicture.Visible = True
SentLabel.Visible = True
SentTimer.Start()
Else
MsgBox("Port not available")
End If
I Hope My Answer Was Useful To You.
Important Note
Port value change from time to another and from computer to another.
I will show you how to know port value of your device by pictures.
1:Enter to Device Manager from Control Panel.
2:Right click on the device, and choose Properties.
3:Choose Modem tap, and look for port name, and use it in your application.

Convert traditional vb to vb.net 2010

Can someone help me to convert this to vb.net 2010 code. I have a window that has textbox1, i found this code bt cldnt figure ho i can write it in vb.net 2010
Imports System.Diagnostics
Module Module1
Sub Main()
Dim pc As New PerformanceCounterCategory("Network Interface")
Dim instance As String = pc.GetInstanceNames(0)
Dim bs As New PerformanceCounter("Network Interface", "Bytes Sent/sec", instance)
Dim br As New PerformanceCounter("Network Interface", "Bytes Received/sec", instance)
Console.WriteLine("Monitoring " & instance)
Do
Dim kbSent As Integer = bs.NextValue() / 1024
Dim kbReceived As Integer = br.NextValue() / 1024
Console.WriteLine(String.Format("Bytes Sent {0}k Bytes Received {1}k", kbSent, kbReceived))
Threading.Thread.Sleep(1000)
Loop
End Sub
End Module
It looks like a console app,
What you may be struggling with is how to get the data into your textbox?
Where-as in your sample it was being written to the console window.
Simply change THESE lines and you should be fine.
Console.WriteLine("Monitoring " & instance)
Change the above for:
Texbox1.text = "Monitoring " & instance & vbcrlf
Also change this line
Console.WriteLine(String.Format("Bytes Sent {0}k Bytes Received {1}k", kbSent, kbReceived))
change it to:
Textbox1.Text = Textbox1.Text & String.Format("Bytes Sent {0}k, Bytes Received {1}k", kbSent, kbReceived)

Error 440 in Visual Basic Application

There is an old VB application running at one of my clients.
An exception is throws in this peice of code:
cn=GetIndexDatabaseConnectionString()
sSql="SELECT * FROM Arh_Naroc WHERE StNarocila = '" & isci & "'"
rs=CreateObject("ADODB.Recordset")
Call rs.Open(sSql,cn)
The exception happens in rs.Open() function. "Error number 440 occured."
This are SBL scripts for KOFAX engine and it's many years old.
The whole SW was transferred from old XP computer to Windows 7 and looks like there are problems everywhere.
Can some one help me determine what is the problem here. At least if I could get a proper error message back in msgbox would be most helpful.
EDIT:
This is the connection string function.
Function GetIndexDatabaseConnectionString
Dim objXmlDocument As Object
Dim objXmlGlobalSettingsFileParh As Object
Dim objXmlIndexDatabaseConnectionString As Object
Dim strGlobalSettingsFilePath As String
Dim strTemp As String
Const strSettingsFilePath = "C:\Data\LocalDocsDistibutingSystem\Settings.xml"
Set objXmlDocument = CreateObject("MSXML2.DOMDocument")
objXmlDocument.Load strSettingsFilePath
Set objXmlGlobalSettingsFileParh = objXmlDocument.selectSingleNode("DocsDistributingSystem/GlobalSettingsFilePath")
strGlobalSettingsFilePath = objXmlGlobalSettingsFileParh.childNodes(0).Text
Set objXmlGlobalSettingsFileParh = Nothing
Set objXmlDocument = Nothing
Set objXmlDocument = CreateObject("MSXML2.DOMDocument")
objXmlDocument.Load strGlobalSettingsFilePath
Set objXmlIndexDatabaseConnectionString = objXmlDocument.selectSingleNode("DocsDistibutingSystem/AscentCapture/IndexDatabase/ConnectionString")
strTemp = objXmlIndexDatabaseConnectionString.childNodes(0).Text
Set objXmlIndexDatabaseConnectionString = Nothing
Set objXmlDocument = Nothing
GetIndexDatabaseConnectionString = strTemp
End Function
This is the relevant line from Settings.xml:
<ConnectionString> Provider=OraOLEDB.Oracle;Data Source=LINO2;User Id=****;Password=****;OLEDB.NET=True; </ConnectionString>
The real data is masked with *. The connection to Oracle appears to be ok. I created ODBC and linked server to sql using the provider and connection data. It works. It must be something missing installed on the computer for ADODB to work...
The connection appears to be working OK. There is no error when its initialized.
The error happens in Call rs.Open(sSql, cn). All i want is the detailed error message when the error happens...
Many thanks.
As it states on MS Knowledge Base
An error occurred while executing a method or getting or setting a
property of an object variable. The error was reported by the
application that created the object. Check the properties of the Err
object to determine the source and nature of the error. Also try using
the On Error Resume Next statement immediately before the accessing
statement, and then check for errors immediately following the
accessing statement.
So as they suggest check the Err object, in a similar fashion to:
If Err.Number <> 0 Then
Msg = "Error: " & Str(Err.Number) & ", generated by " _
& Err.Source & ControlChars.CrLf & Err.Description
MsgBox(Msg, MsgBoxStyle.Information, "Error")
End If
So this will bring back the error in a MsgBox, however you can just use Response.Write if you want it easier to copy & paste etc..
to get the error description you can do as follows :
Function GetIndexDatabaseConnectionString()
On Error GoTo Errorfound
'your
'function
'body
Exit Function
Errorfound:
With Err
MsgBox "Source: " & .Source & vbCrLf & "Desc: " & .Description, vbCritical, "Error " & CStr(.Number)
End With 'Err
End Function