Solved

VB Inet Control

Posted on 2003-11-06
11
2,046 Views
Last Modified: 2013-12-26
Hi everyone, I'm new  to VB world! I am using a simple Inet Control and the syntax is below
response = Inet1.OpenURL(URL, icString)
             MsgBox (response)

but somehow it doesn't connect to the URL
Do I need to set up something or activate the control or something?
any idea?

thanks
0
Comment
Question by:Majusri
  • 5
  • 4
  • 2
11 Comments
 
LVL 9

Expert Comment

by:Dang123
ID: 9695477
Try this

    response = Inet1.OpenURL(URL, icString)
    Do While Inet1.StillExecuting
        DoEvents
    Loop
    MsgBox (response)


Dang123
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9695518
Majusri,
    It takes a little time to establish the connection and return the contents of the page you are requesting. The loop will allow your program to wait for the page to be returned. You could also put code into the StateChanged event for the control. That would prevent you from using CPU cycles in a wait loop. The method you pick would depend on what you want to accomplish.

Dang123
0
 

Author Comment

by:Majusri
ID: 9715156
well it not really working! I implement this peice of code

Do While Inet1.StillExecuting
                DoEvents
             Loop

but it giving me the error :
Gopher - Attribute not found
the error code is 12057

it seem like sometime it work and most of the time it given this error. Anyone know why?

Majusri
0
 
LVL 9

Accepted Solution

by:
Dang123 earned 50 total points
ID: 9715201
Majusri,
Can you post your full form that is giving you trouble?

1. Start notepad.
2. File -> Open
3. Find the .frm file containing your form.
4. Change any sensitive information - passwords or ids to something else
5. Select all the text
6. Copy it and paste it into the comment box here.

(** Remember do NOT save the file if you changed anything in step 4 **)

Dang123
0
 

Author Comment

by:Majusri
ID: 9715248
VERSION 5.00
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Begin VB.Form uploadFile
   Caption         =   "uploadForm"
   ClientHeight    =   6645
   ClientLeft      =   3435
   ClientTop       =   3030
   ClientWidth     =   11100
   Icon            =   "uploadFile.frx":0000
   ScaleHeight     =   6645
   ScaleWidth      =   11100
   Begin InetCtlsObjects.Inet Inet1
      Left            =   4080
      Top             =   2040
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      Protocol        =   5
      RemotePort      =   443
      URL             =   "https://"
   End
   Begin VB.CommandButton Command1
      Caption         =   "upload now!"
      Height          =   495
      Left            =   3720
      TabIndex        =   0
      Top             =   1320
      Width           =   1215
   End
End
Attribute VB_Name = "uploadFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
ListFile "F:/"
End Sub
Public Sub ListFile(ByVal DirName As String)

Dim filesys As Object
Dim txtStream As Object
Dim files
Dim fileName
Dim File
Dim strXML As String
Dim URL As String
Dim folder
Dim response As String
Dim fileLoad As String
Dim pass As String


 On Error Resume Next
    If (Dir$(DirName, vbDirectory) = "") Then Exit Sub
    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set folder = filesys.GetFolder(DirName)
 
     Set files = folder.files
       If files.Count <> 0 Then

      For Each File In files
       Set f = filesys.GetFile(File)
       Set txtStream = filesys.openTextFile(f)
       setFileName = f.Name

            If Not txtStream.AtEndOfStream Then
               Do While Not txtStream.AtEndOfStream
                  strXML = strXML + txtStream.readline
               Loop
            End If
             URL = "https://localhost/getXML.asp?filename=" & setFileName & "&" & "XML=" & strXML
             
             Inet1.Cancel
             Inet1.Protocol = icHTTPS
             Inet1.AccessType = icDirect
             Inet1.URL = URL
             response = Inet1.OpenURL(URL, icString)
             
             Loop
            fileLoad = fileLoad + response
             strXML = Clear
             DoEvents
           
    Next
 End If
 MsgBox (fileLoad)
 
End Sub




Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim status As String
Select Case State


  Case icError
 
    MsgBox (Inet1.ResponseCode & "   " & Inet1.ResponseInfo)
 
End Select


End Sub
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Majusri
ID: 9715297
ignore the Loop after the Inet1.OpenURL
 
0
 

Author Comment

by:Majusri
ID: 9715948
does anyone know why did I get this error

error code: 12057
error message: Gopher - Attribute not found
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9716652
Majusri,
    Were you able to solve the 12057 error? I was still looking at the code you posted above. I don't have a server I can test it against, so it was taking a bit longer.

    By the way, if you have line breaks in your XML files, I think you may have a problem with them since you are passing them in your URL. Also since a URL has a maximum length of 2,083 I was also considering that if your files are large it may be causing problems also.

Dang123


0
 

Author Comment

by:Majusri
ID: 9717036
Thanks Dang123!
 
   The problem being is the Revocation List(SSL) is not available therefore the Inet Control throws that error. I have clue why is that but I have tried a different server and it working quite well. So thank alot for your help.

Majusri - VanThu
0
 

Expert Comment

by:aramos_Takion
ID: 37850176
Hi,  

Could I ask how did you fix the issue?  I have the same problem in a similar environment
Error 11 Gopher Attribute not found

Many thanks
Antonio
0
 

Expert Comment

by:aramos_Takion
ID: 37850193
This is my code:

VERSION 5.00
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Begin VB.Form frmRecu
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   615
   ClientLeft      =   15
   ClientTop       =   15
   ClientWidth     =   1200
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   615
   ScaleWidth      =   1200
   StartUpPosition =   3  'Windows Default
   Begin VB.Timer timMaxEspera
      Left            =   630
      Top             =   0
   End
   Begin InetCtlsObjects.Inet InetRecPub
      Left            =   45
      Top             =   0
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
   End
End
Attribute VB_Name = "frmRecu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' DTA (RT)
Private blnDatosRecibido As Boolean
Private strDatosEnt As String
Private mlngInterval As Long
Private Sub ActivaTemporizador()
 
  On Error GoTo errActivaTemporizador
 
  If mlngInterval <> 0 Then timMaxEspera.Enabled = True
 
errActivaTemporizador:

  If Err.Number <> 0 Then
    strMsgError = "Error al inicializadar el temporizador"
  End If
End Sub
Public Property Let MaxTmpEspera(ByVal lngMaxTmp As Long)
 
  On Error GoTo errMaxTmpEspera
 
  lngMaxTmp = lngMaxTmp * 1000
  If lngMaxTmp < 1 And lngMaxTmp > 60000 Then
    strMsgError = "[ComPetHTTP:frmRecu:MaxTmpEspera] Se estableció un tiempo de espera incorrecto " & lngMaxTmp
    mlngInterval = 0
  Else
    timMaxEspera.Interval = lngMaxTmp
    mlngInterval = lngMaxTmp
  End If
 
errMaxTmpEspera:

  If Err.Number Then
    strMsgError = "Error al establecer el tiempo máximo de espera " & lngMaxTmp
  End If

End Property

Public Function RecContURL(ByRef stCont As String, ByVal stUrl As String, _
                           Optional ByVal stPuerto As String) As Boolean
                           
  On Error GoTo errRecContURL
 
  With InetRecPub
    ' Le estoy estableciendo el tiempo maximo de espera
    .RequestTimeout = 15
    .Protocol = icHTTP
    If stPuerto <> "" Then .RemotePort = stPuerto
    .URL = stUrl
    stCont = .OpenURL()
  End With
  RecContURL = True
 
errRecContURL:
 
 If Err.Number <> 0 Then
    stCont = Err.Description
    RecContURL = False
 End If

End Function

Public Function SendDataUrl(ByRef strDatResp As String, ByRef arrDatos() As String, _
                            ByVal strURL As String, ByVal strPuerto As String) As Boolean
 
  Dim strDAtos As String
  Dim lngCampo As Long
 
  On Error GoTo errRecContURL
 
  For lngCampo = 0 To UBound(arrDatos) Step 2
    If strDAtos <> "" Then strDAtos = strDAtos & "&"
    strDAtos = strDAtos & arrDatos(lngCampo) & "=" & arrDatos(lngCampo + 1)
  Next lngCampo
 
 
  With InetRecPub
   .RequestTimeout = 15
   .Protocol = icHTTPS 'icHTTP
   If strPuerto <> "" Then .RemotePort = strPuerto
   blnDatosRecibido = False
   .Execute strURL, "POST", strDAtos, "Content-Type: application/x-www-form-urlencoded"
   ActivaTemporizador
   
   Do While Not blnDatosRecibido And strMsgError = ""
    DoEvents
   Loop
   
   If blnDatosRecibido And strMsgError = "" Then
    strDatResp = strDatosEnt
    SendDataUrl = True
   End If
  End With
   
errRecContURL:
 
 If Err.Number <> 0 Then
   If strMsgError = "" Then
        strMsgError = "[ComPetHttp: SendDataUrl] Error(" & Err.Description & ")" & _
                  "Cadena:" & Join(arrDatos, "#$#")
    End If
    SendDataUrl = False
 End If
   
End Function

Private Sub Form_Load()
  blnFormLoad = True
  mlngInterval = 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
  blnFormLoad = False
End Sub

Private Sub InetRecPub_StateChanged(ByVal State As Integer)
  ' Cuando termine correctamente, recuperaré los datos devueltos por la página
  Dim strBloqDat As String
 
  On Error GoTo errInetRecPub_StateChanged
 
  Select Case State
    Case icResponseCompleted
      strBloqDat = InetRecPub.GetChunk(1024, icString)
      Do While strBloqDat <> ""
        strDatosEnt = strDatosEnt & strBloqDat
        strBloqDat = InetRecPub.GetChunk(1024, icString)
      Loop
      blnDatosRecibido = True
      timMaxEspera.Enabled = False
    Case icError
      strMsgError = "No se pudo conectar con el servidor especificado " & InetRecPub.ResponseInfo
     
  End Select

errInetRecPub_StateChanged:
 
  If Err.Number <> 0 Then
    If strMsgError = "" Then strMsgError = "Error en InetRecPub_StateChanged(" & _
                                           Err.Description & ")"
  End If
End Sub

Private Sub timMaxEspera_Timer()
  strMsgError = "Agotado el tiempo maximo de espera"
  lngErr = 10001
  timMaxEspera.Enabled = False
End Sub
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now