Last post Nov 03, 2009 10:49 AM by atconway
Nov 02, 2009 02:36 PMfirstname.lastname@example.org|LINK
I need to make a new class...
Here is the code that needs the class:
Private Sub SmsFunc()
Dim sender As String = "Sendega"
Dim recipient As String = "4799xxxxxx"
Dim message As String = "My testmessage"
Dim priceGroup As Integer = 0
Dim flash As Integer = 0
Dim smsClass As New SmsClass()
Dim res As String = smsClass.sendSms(sender, recipient, message, priceGroup, flash)
Dim resint As Integer
If Int32.TryParse(res, resint)
Response.Write("Sms sent successfully. (" & res & ")")
Else Response.Write("Sms failed. Error description: " & res)
Public Class SmsClass
Dim CID As String = "xx"
Dim password As String = "xxxxxx"
Public Function SendSms(ByVal msgsender As String, ByVal recipients As String, ByVal message As String, ByVal priceGroup As Integer, ByVal flash As Integer) As String
Dim serverResult As String
Dim foo As Integer
Dim serverRequest As String
serverRequest = "http://api.sendega.no/SendSMS.asp" _
& "?CID=" & CID _
& "&Password=" & password
If Integer.TryParse(msgsender, foo) Then
serverRequest = serverRequest & "&fromNumber=" & msgsender
serverRequest = serverRequest & "&fromAlpha=" & msgsender
serverRequest = serverRequest & "&recipient=" & recipients _
& "&Msg=" & message _
& "&priceGroup=" & priceGroup _
& "&flash=" & flash
Using wc As New System.Net.WebClient
serverResult = wc.DownloadString(serverRequest)
Catch ex As Exception
Return "Error occured while connecting to Sendega [" & ex.Message & "]"
Dim xDoc As New XmlDocument()
Dim success As XmlNodeList
success = xDoc.GetElementsByTagName("success")
Dim xRes As XmlNodeList
If success(0).InnerText.Equals("true") Then
xRes = xDoc.GetElementsByTagName("msgid")
xRes = xDoc.GetElementsByTagName("errormsg")
Nov 02, 2009 05:24 PM|N_EvilScott|LINK
Create a new vb code file in your App_Code folder and call it SmsClass.
Erase everything inside of it, and paste your class that you put in your post above inside that file instead and then save it.
Now all your aspx pages will have access to that class from your code behind pages.
i.e (Default.aspx.vb file) etc...
Nov 02, 2009 06:03 PMemail@example.com|LINK
I've put this on the top:
<%@ Page Language="VB" %>
<%@ import Namespace="SmsClass" %>
But stil the same :(
Nov 02, 2009 06:35 PM|N_EvilScott|LINK
I see what your trying to do.
You are tryin to access the class directly from the aspx page, that is not what the classes are meant to do. You have access to your class from your aspx code behind file.
Your class looks like it just sends an SMS message of some type So it would look like this... as an example
Lets say you have a text box to store your information in. Looking at the class it looks like its trying to capture a few pieces of information:
1) Message Sender
So lets say you have 5 text boxes to capture that data, and then a button the user can click on to send the data.
The button click fires an event handler so in your code behind file you would simply put the following code..
// this code goes inside of your Button_Click event handler function
SmsClass.SendSms(....input data here...);
And that will initiate your class to send an Sms message with your class.
Nov 03, 2009 10:49 AM|atconway|LINK
You will have a much easier time implementing this code if you utilize the code file behind the page, rather than trying to insert all of this code into the .asmx file using server tags.
If you are new to Visual Studio there are several ways to access the .vb code behind file.
In your case you will need something similar to the following code to instantialte your class and access its methods:
'Create a new instance of the SmsClass
Dim SmsClassOps As New SmsClass()
'Call the 'SensSms' method passing in the class level defined variables
Dim Result As String = String.Empty
Result = SmsClassOps.SendSms(sender, recipient, message, priceGroup, flash)
Hope this helps!