Avatar billede slapstick Nybegynder
23. maj 2004 - 04:14 Der er 8 kommentarer og
1 løsning

poste til html form fra vb

jeg vil gerne poste til en html form fra vb og så gemme den side man får igen som en fil lokalt på min maskine
nogen der har en ide?
Avatar billede mcgoat Nybegynder
23. maj 2004 - 05:20 #1
hvordan mener du med "at poste"? ligesom php $_POST eller bare at skrive til en html fil?
Avatar billede slapstick Nybegynder
23. maj 2004 - 12:36 #2
jeg mener at ligesom når man udfylder en html form og trykket submit
det vil jeg gøre inde fra vb og den side man så får returneret vil jeg gemme som htmlfil
Avatar billede martin_moth Mester
24. maj 2004 - 14:41 #3
Har du adgang til den html-side der skal udfyldes? Hvis ikke, er det vist ikke sådan noget man bare lige gør...
Avatar billede thesurfer Nybegynder
24. maj 2004 - 21:34 #4
Hmm.. se lige:

objInet.Execute strURL, "POST", strData, strHeaders

Kilde: http://www.textforce.com/sms_api/vb_example.htm
Avatar billede thesurfer Nybegynder
24. maj 2004 - 21:35 #5
objInet = Microsoft Internet Control
strUrl = siden der skal submittes til
POST = kommando til at submitte (hente data er "GET")
strData = data der skal submittes
strHeaders = headers, ville jeg gætte på :-)
Avatar billede thesurfer Nybegynder
24. maj 2004 - 21:35 #6
rettelse: objInet = Microsoft Internet Transfer Control
Avatar billede slapstick Nybegynder
25. maj 2004 - 10:21 #7
smukt thesurfer ser ud til at være det jeg skal bruge
smid et svar så får du point :)
Avatar billede thesurfer Nybegynder
25. maj 2004 - 18:13 #8
OK, svar :-)
Avatar billede thesurfer Nybegynder
25. maj 2004 - 21:15 #9
Takker for points. :-)


-- Skulle http://www.textforce.com/sms_api/vb_example.htm gå ned, er indholdet af siden her:


------------------------------------------------------------------------------------------


VB example. It's not packaged up as it was provided by another client that is happy to share it.

Please note that technical support is not available for the code.



-----Start-----



The function has been created for Access 2000, but as Access uses the same VB engine as VB6, this should work OK.



You will need to create a reference to Microsoft Internet Transfer Control (msinet.ocx) as this is used for HTTP.



Create a form called frmInet containing a Microsoft Internet Transfer Control named Inet1

Add this code to form:

Option Explicit

Dim intState As Integer

Dim strPageReturn



Private Sub Inet1_StateChanged(ByVal State As Integer)

On Error GoTo ErrInet1_StateChanged

' Retrieve server response using the GetChunk

' method when State = 12.

Dim vtData As Variant

Dim strData As String

Dim bDone As Boolean: bDone = False



intState = State

Select Case State

' ... Other cases not shown.

Case icError ' 11

  ' In case of error, return ResponseCode and

  ' ResponseInfo.

  vtData = Inet1.ResponseCode & ":" & _

  Inet1.ResponseInfo

Case icResponseCompleted ' 12



  ' Get first chunk.

  vtData = Inet1.GetChunk(1024, icString)

  DoEvents



  Do While Not bDone

      strData = strData & vtData

      ' Get next chunk.

      vtData = Inet1.GetChunk(1024, icString)

      DoEvents



      If Len(vtData) = 0 Then

        bDone = True

      End If

  Loop

  strPageReturn = strData

End Select



ExitInet1_StateChanged:

  Exit Sub

ErrInet1_StateChanged:

  MsgBox "Error " & Err.Number & ": " & Err.Description

  Resume ExitInet1_StateChanged

End Sub



Property Get ControlState() As Byte

  ControlState = intState

End Property



Property Get PageReturn() As String

  PageReturn = strPageReturn

End Property


------------------------------------------------------------------------------------------




Create a function to be called for sending SMS



Function SendSMS(ByVal strMobile As String, ByVal strMessage As String, Optional strReturn As String, Optional IsHourGlass As Boolean = False) As Byte

‘Function to send an SMS text message using  Text Force SMS gateway.

‘Returns a code to show if successful 1=successful, anything else shows an error

‘strMobile is a string containing one or more mobile numbers to send message to

‘strMessage is a string containg the message

‘strReturn is a string returning an error description, if not want function to show errors with message box replace lines

            starting msgbox to strReturn =

‘IsHourGlass is flag to tell function whether to set hourglass on screen and clear after function is finished

‘Supplied as is by:

‘Datastore Computing Ltd, info@go-dcl.co.uk, Tel 07768 901944



On Error GoTo ErrSMSSend

Dim objInet As Inet

Dim strHeaders As String

Dim strData As String

Dim datStart As Date

Dim booTimeOut

Dim intSendSMS As Integer

Dim strUserName As String

Dim strPassword As String

Dim strURL As String

Dim strHeader



'If calling function has not declared its use of hourglass

'set the hourglass to show

If Not IsHourGlass Then

  DoCmd.Hourglass True

End If



'Get the passwords etc to use

strUserName = “ENTER YOUR USERNAME SUPPLIED BY  TEXT FORCE HERE”

strPassword = “ENTER YOUR PASSWORD SUPPLIED BY  TEXT FORCE  HERE”

strURL = “ENTER URL FOR  TEXT FORCE GATEWAY HERE”

strHeader = “ENTER WHO YOU WANT MESSAGE TO SHOW AS COMING FROM”

 

'Check message is sendable

If Len(strMessage) > 160 Then

  MsgBox "Unable to send SMS as message is longer than 160 characters.", vbInformation

  GoTo ExitSMSSend

ElseIf strMessage = "" Then

  MsgBox "There is no message to send.", vbInformation

  GoTo ExitSMSSend

End If

If strMobile = "" Then

  MsgBox "You must include at least one mobile number to send message to.", vbInformation

  GoTo ExitSMSSend

End If



'Format the numbers to comma delimited with country code and no leading zero and no spaces

strMobile = Replace(strMobile, " ", "")

If Not IsNumeric(Replace(strMobile, ",", "")) Then

  MsgBox "You can only send SMS messages to numbers"

  GoTo ExitSMSSend

End If

If Left(strMobile, 2) = "00" Then

  strMobile = Right(strMobile, Len(strMobile) - 2)

ElseIf Left(strMobile, 1) = "0" Then

  strMobile = "44" & Right(strMobile, Len(strMobile) - 1)

End If

strMobile = Replace(strMobile, ",00", ",")

strMobile = Replace(strMobile, ",0", ",44")



'Make the message work with inet as & will be treated as a new variable. %26 will be changed back to & before sending

strMessage = Replace(strMessage, "&", "%26")



'Send the message

DoCmd.OpenForm "frmInet", , , , , acHidden

Set objInet = Forms!frmInet!Inet1.Object

strData = "username=" & strUserName & "&password=" & strPassword & "&originator=" & strHeader & "&numberlist=" & strMobile & "&message=" & strMessage

strHeaders = "Content-Type: application/x-www-form-urlencoded" & vbCrLf

objInet.Execute strURL, "POST", strData, strHeaders



'Look for return code or wait for time out and show error

datStart = Now

Do

  DoEvents

  booTimeOut = (DateDiff("n", datStart, Now()) >= 2) ‘Set for 2 minute timeout, adjust value after >= to max minutes to wait

Loop Until Forms!frmInet.ControlState = 12 Or booTimeOut

If booTimeOut Then

  intSendSMS = 10

  strReturn = "Timeout"

Else

  strReturn = Trim(Replace(Replace(Replace(Forms!frmInet.PageReturn, Chr(9), ""), Chr(10), ""), Chr(13), ""))

  If IsNumeric(Forms!frmInet.PageReturn) Then

    intSendSMS = CInt(Forms!frmInet.PageReturn)

  Else

    intSendSMS = 11

  End If

End If



If intSendSMS = 0 Then

  SendSMS = 1

Else

  SendSMS = intSendSMS

End If

Select Case intSendSMS

  Case 0

    MsgBox "SMS Message sent.", vbInformation

  Case 99

    MsgBox "Unable to send message due to error with mobile number. Please confirm mobile number.", vbInformation

  Case 98

    MsgBox "Unable to send message due to an unexpected error. The web site for sending the message is expecting a different layout.", vbInformation

  Case 97

    MsgBox "Unable to send message as there is not enough credit available.", vbInformation

  Case 96

    MsgBox "Unable to send message as the web site for sending the message has responded that the username or password is incorrect. Please contact system administrator.", vbInformation

  Case 10

    MsgBox "Unable to send message as the web site for sending the message is not responding, please try later.", vbInformation

  Case 11

    MsgBox "There was an unexpected problem with sending the message. The web site for sending the message responded as follows (please note the message and pass on to system administrator." & Chr(13) & Chr(10) & Chr(13) & Forms!frmInternetUpdate.PageReturn, vbInformation

  Case Else

    MsgBox "There was an unexpected problem sending the message, this may not have been sent. Return code = " & intSendSMS & ". Please pass this code on to system administrator.", vbInformation

End Select



ExitSMSSend:

  On error resume next

  DoCmd.Close acForm, "frmInternetUpdate"

  'If calling function has not declared its use of hourglass

  'set the hourglass to hide

  If Not IsHourGlass Then

    DoCmd.Hourglass False

  End If

  Exit Function

ErrSMSSend:

  MsgBox "Error " & Err.Number & ": " & Err.Description

  SendSMS = 20

  Resume ExitSMSSend

End Function



 

Paul Edwards

Datastore Computing Ltd

Tel +44 (0)1268 473473

Mobile + 44(0)7768 901944

Email paul@go-dcl.co.uk

Web Site www.go-dcl.co.uk
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester