Answered by:
Public Class

Question
-
User-103886592 posted
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) Then Response.Write("Sms sent successfully. (" & res & ")") Else Response.Write("Sms failed. Error description: " & res) End IF End Sub
But here is the code for the class, how do i insert this the aspx document or is it a different formart?? any ideas on how this file should look like? And where do i place this file??
Imports Microsoft.VisualBasic Imports System.Xml 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 Else serverRequest = serverRequest & "&fromAlpha=" & msgsender End If serverRequest = serverRequest & "&recipient=" & recipients _ & "&Msg=" & message _ & "&priceGroup=" & priceGroup _ & "&flash=" & flash Try Using wc As New System.Net.WebClient serverResult = wc.DownloadString(serverRequest) End Using Catch ex As Exception Return "Error occured while connecting to Sendega [" & ex.Message & "]" End Try Dim xDoc As New XmlDocument() xDoc.LoadXml(serverResult) Dim success As XmlNodeList success = xDoc.GetElementsByTagName("success") Dim xRes As XmlNodeList If success(0).InnerText.Equals("true") Then xRes = xDoc.GetElementsByTagName("msgid") Else xRes = xDoc.GetElementsByTagName("errormsg") End If Return xRes(0).InnerText End Function End Class
Monday, November 2, 2009 2:36 PM
Answers
-
User-952121411 posted
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.
- Right-click the .aspx page in 'Solution Explorer' and select 'View Code'
- Manually double click the file in Solution Explorer, which for the page 'Default.aspx' will be called 'Default.aspx.vb'
- In 'Design View' of the page, right click anywhere and select 'View Code'
- Or, to go directly to the event of a control like a button, find the button in Design View of the .aspx page, and double click it. That will take you directly to the event handler for that button (the event handler is the wired up code that will be called on the server when the user clicks that button.
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!- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, November 3, 2009 10:49 AM
All replies
-
User-1528094326 posted
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...
Monday, November 2, 2009 5:24 PM -
User-103886592 posted
I've put this on the top:
<%@ Page Language="VB" %> <%@ import Namespace="SmsClass" %>
But stil the same :(
Monday, November 2, 2009 6:03 PM -
User-1528094326 posted
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
2) Recipient
3) Message
4) Price
5) Flash
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.
Monday, November 2, 2009 6:35 PM -
User-952121411 posted
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.
- Right-click the .aspx page in 'Solution Explorer' and select 'View Code'
- Manually double click the file in Solution Explorer, which for the page 'Default.aspx' will be called 'Default.aspx.vb'
- In 'Design View' of the page, right click anywhere and select 'View Code'
- Or, to go directly to the event of a control like a button, find the button in Design View of the .aspx page, and double click it. That will take you directly to the event handler for that button (the event handler is the wired up code that will be called on the server when the user clicks that button.
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!- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, November 3, 2009 10:49 AM