API in Visual Basic 6 working fine!

hi forum, after much searching, I found an example for the management of the api in vb6 posted by Royce3, after some minor alterations to make to achieve it to work well, AUI I leave so they can experience and that You will not find any echo in vb6 to handle the api. I hope this will be useful, and discuss their progress, I keep working !!!..

Greetings.
TESTAPIVB6.JPG
MKT API Test.rar (11.4 KB)

good job!

its not work

his return this msg

(Connecting)
ws_Error: Connection is forcefully rejected

did you enable the API on RouterOS?

took 9 months trying to fix it, I knew I had to do to enable the API

tanks normis

WORKS PERFECTLY !!!

I’ve learned java and VB.NET, but I think, I’m still loving this classic things.

Spend one year to make API in visual basic, but I got nothing. :laughing:

ip - service

did you enable api?

i used ros 5.8 and working properly.

Great job, TS.

The script is working fine for me, the API is enabled and I can log in the router.

When I click SEND, I can see the same results. The probleme is when I click again on SEND, I get the OLD result + the new one. I cleared the text field before clicking SEND (txtout.text=“”), but same problem. It seem the buffer is not clearing after the command is executed. I suspect the inbuf1 variable.


Thanks for your help

is this script run correcly at v 5.12?

Yes, working fine!!!

what wrong with mine?
its error when copile to make .exe file

@ax045Y
Do not use Package and Deployment Wizard to compile project, use VB6 IDE ‘File/Make…’ command instead.
In this case compiler shows you what and where is wrong with code.
This API example works fine, problem is with ‘CRAM_MD5’ function in ‘MD5.cls’.
Remove this function and you will be able to compile this example to .EXE.

HTH,

:smiley:
thanks..
anyway i have new problem.
what command to enable user?

hmm,
so this api just can do 1 line command?

do you have a vb.net source

Thanx lucho512 good job

Doris, i have your problem also, and after a hours i got this

change this

Private Sub ws_DataArrival(ByVal sent$)
.
.
.
end sub

into this

Private Sub ws_DataArrival(ByVal bytesTotal As Long)
    If bErr Then Exit Sub
    Dim ar() As Byte, i&
    ReDim ar(0 To bytesTotal - 1)
    ws.GetData ar, vbByte, bytesTotal
    On Error Resume Next
    Err.Clear
    On Error GoTo 0
    inbuf1 = ar
    Dim WordLen&, StartIdx&, Idx&
    StartIdx = 0
    Do While True
        Idx = StartIdx
        WordLen = CalcWordLen(inbuf1, Idx)
        If WordLen < 0 Then
            Exit Do
        End If
        If WordLen = 0 Then
            SentenceArrived (inbuf2)
            inbuf2 = ""
        Else
            If inbuf1(Idx) = Asc("=") Then
                inbuf2 = inbuf2 & " "
            End If
            For i = 0 To WordLen - 1
                inbuf2 = inbuf2 & Chr(inbuf1(Idx + i))
            Next
        End If
        StartIdx = Idx + WordLen
    Loop
End Sub

that solve my problem,

and for good looking change this :

Private Sub SendCommand(ByVal sCmd$)
.
.
.
End Sub

into this

Private Sub SendCommand(ByVal sCmd$)
    Dim ar$(), i&, buf() As Byte
    Out Replace(sCmd, " ", vbCrLf )
    ar = Split(sCmd, " ")
    For i = 0 To UBound(ar)
        EncodeWord buf, ar(i)
    Next
    EncodeWord buf, ""
    If ws.State = sckConnected Then ws.SendData buf
End Sub

im working vb api to create and generate hotspot user, because with user manager maximal active session for lvl4 is 20, its better to use /ip/hotspot than /tool/user-manager, hotspot active user can up to 200,

wait for my next reply with full VB code for create user, im sory for my bad english, this is my firts post :smiley:

no u can change a line white space, and read about api query here http://wiki.mikrotik.com/wiki/API#Query_word

ax045Y wrote:

thanks..
anyway i have new problem.
what command to enable user?
hmm,
so this api just can do 1 line command?

no u can change a line white space, and read about api query here http://wiki.mikrotik.com/wiki/API#Query_word



Its work

/ip/hotspot/user/add O =name=user1 O =password=111 O =limit-uptime=00:01:00

Try this:
/ip/hotspot/user/add O =name=user1 O =password=111 O =limit-uptime=00:01:00

Olá,

Using this program, which the command to remove a joined via IP and also how to add?

Olá,

Using this program, which the command to remove a joined via IP and also how to add?

Obrigado!