?小小静?
2024-11-15 07:19:33
最佳回答
这是一个获取股票实时报价的程序,这程序有一个窗体,一个模块窗体代码:option explicitdim g_strsymbol as stringdim nrow as integerdim csymboll**t as collectiondim casyncsymboll**t as collectiondim cregsymbols as collectiondim bquotesreg**tered as booleanprivate sub asynctimer_timer() if basync**ailable then if casyncsymboll**t.count < 1 then if bregquotes then reg**tersymbols csymboll**t end if asynctimer.enabled = false basync**ailable = false exit sub end if dim stritem as string stritem = "~getquote," & casyncsymboll**t.item(1) casyncsymboll**t.remove 1 dde_request "q", stritem, true basync**ailable = false end ifend subprivate sub command1_click() dim bloop as boolean dim strfieldvalue as string dim ncomma as long bloop = true dim ncounter as integer dim svalue as string dereg**terregsymbols bquotesreg**tered = false flexgrid1.clear do while csymboll**t.count() > 0 csymboll**t.remove 1 loop do while casyncsymboll**t.count() > 0 casyncsymboll**t.remove 1 loop svalue = lblsymbol do while bloop = true ncomma = instr(svalue, ",") if (ncomma < 1) then if (len(svalue) > 0) then bloop = false strfieldvalue = svalue svalue = right(svalue, len(svalue) - ncomma) else exit do end if else strfieldvalue = left(svalue, ncomma - 1) svalue = right(svalue, len(svalue) - ncomma) end if casyncsymboll**t.add strfieldvalue csymboll**t.add strfieldvalue loop flexgrid1.cols = 10 'flexgrid1.colwidth(0) = 2000 'flexgrid1.colwidth(5) = 1500 flexgrid1.fixedcols = 0 flexgrid1.fixedrows = 1 if (csymboll**t.count() > 0) then flexgrid1.rows = csymboll**t.count() + 1 else flexgrid1.rows = 2 end if flexgrid1.textarray(0) = "sym" flexgrid1.textarray(1) = "last" flexgrid1.textarray(2) = "chg" flexgrid1.textarray(3) = "bid" flexgrid1.textarray(4) = "ask" flexgrid1.textarray(5) = "last size" flexgrid1.textarray(6) = "high" flexgrid1.textarray(7) = "low" flexgrid1.textarray(8) = "vol" flexgrid1.textarray(9) = "last time" dim stritem as string if bregquotes then bquotesreg**tered = true end if if optasync.value = true then asynctimer.enabled = true if csymboll**t.count > 0 then stritem = "~getquote," & casyncsymboll**t.item(1) casyncsymboll**t.remove 1 dde_request "q", stritem, true end if else 'topic = "q" item = "~getquote,msft" dim ncount as integer dim x as integer x = 1 ncount = csymboll**t.count() do while ncount + 1 > x stritem = "~getquote," & csymboll**t.item(x) dde_request "q", stritem, false x = x + 1 loop if bregquotes then reg**tersymbols csymboll**t end if end ifend subprivate sub flexgrid1_click()end subprivate sub form_load() set csymboll**t = new collection set casyncsymboll**t = new collection set cregsymbols = new collection optsync.value = true ''''''''''''''''''''''''''''''''''''''' 'dde init ''''''''''''''''''''''''''''''''''''''' g_linstid = 0 if ddeinitialize(g_linstid, addressof ddecallback, appcmd_clientonly or mf_sendmsgs or mf_postmsgs, 0) then debug.print "dde initialize failure." translateerror else debug.print "dde initialize success." end if 'connect dde dde_createstringhandles "stidde", "q", "" 'open the conversation. if (g_hddeconv = 0) then g_hddeconv = dde_connect end if dde_freestringhandlesend subprivate sub form_unload(cancel as integer)on error resume next dereg**terregsymbols if (g_hddeconv <> 0) then dde_d**connect end ifend subpublic sub updatefield(strsymbol as string, fieldindex as integer, fieldvalue as string) dim bfound as boolean dim nrow as integer dim ncount as integer dim x as integer x = 1 ncount = csymboll**t.count() do while not bfound and x < (ncount + 1) if strsymbol = csymboll**t.item(x) then bfound = true nrow = x end if x = x + 1 loop if bfound then flexgrid1.textarray(fieldindex + (nrow * 10)) = fieldvalue flexgrid1.textarray(nrow * 10) = strsymbol end ifend subprivate sub lblsymbol_change() dim selpos as integer selpos = lblsymbol.selstart lblsymbol = ucase(lblsymbol) lblsymbol.selstart = selposend subprivate sub reg**terallsymbolvalues(csymboll**t as collection) dim x as integer dim ncount as integer ncount = csymboll**t.count() x = 1 do while ncount + 1 > x dde_adv**e "q", csymboll**t.item(x) & "," & q_last, "" dde_adv**e "q", csymboll**t.item(x) & "," & q_chg, "" dde_adv**e "q", csymboll**t.item(x) & "," & q_bid, "" dde_adv**e "q", csymboll**t.item(x) & "," & q_ask, "" dde_adv**e "q", csymboll**t.item(x) & "," & q_last_sz, "" dde_adv**e "q", csymboll**t.item(x) & "," & q_high, "" dde_adv**e "q", csymboll**t.item(x) & "," & q_low, "" dde_adv**e "q", csymboll**t.item(x) & "," & q_vol, "" dde_adv**e "q", csymboll**t.item(x) & "," & q_last_time, "" x = x + 1 loopend subprivate sub reg**tersymbol(strsymbol as string) dde_adv**e "q", strsymbol & "," & q_last, "" dde_adv**e "q", strsymbol & "," & q_chg, "" dde_adv**e "q", strsymbol & "," & q_bid, "" dde_adv**e "q", strsymbol & "," & q_ask, "" dde_adv**e "q", strsymbol & "," & q_last_sz, "" dde_adv**e "q", strsymbol & "," & q_high, "" dde_adv**e "q", strsymbol & "," & q_low, "" dde_adv**e "q", strsymbol & "," & q_vol, "" dde_adv**e "q", strsymbol & "," & q_last_time, "" cregsymbols.add strsymbolend subprivate sub reg**tersymbols(csymbols as collection) dim x as integer dim ncount as integer ncount = csymbols.count() x = 1 do while ncount + 1 > x dde_adv**e "q", csymbols.item(x) & "," & q_last, "" dde_adv**e "q", csymbols.item(x) & "," & q_chg, "" dde_adv**e "q", csymbols.item(x) & "," & q_bid, "" dde_adv**e "q", csymbols.item(x) & "," & q_ask, "" dde_adv**e "q", csymbols.item(x) & "," & q_last_sz, "" dde_adv**e "q", csymbols.item(x) & "," & q_high, "" dde_adv**e "q", csymbols.item(x) & "," & q_low, "" dde_adv**e "q", csymbols.item(x) & "," & q_vol, "" dde_adv**e "q", csymbols.item(x) & "," & q_last_time, "" cregsymbols.add csymbols.item(x) x = x + 1 loopend subprivate sub dereg**terregsymbols() dim x as integer dim ncount as integer ncount = cregsymbols.count() x = 1 do while ncount + 1 > x dde_adv**estop "q", cregsymbols.item(x) & "," & q_last, "" dde_adv**estop "q", cregsymbols.item(x) & "," & q_chg, "" dde_adv**estop "q", cregsymbols.item(x) & "," & q_bid, "" dde_adv**estop "q", cregsymbols.item(x) & "," & q_ask, "" dde_adv**estop "q", cregsymbols.item(x) & "," & q_last_sz, "" dde_adv**estop "q", cregsymbols.item(x) & "," & q_high, "" dde_adv**estop "q", cregsymbols.item(x) & "," & q_low, "" dde_adv**estop "q", cregsymbols.item(x) & "," & q_vol, "" dde_adv**estop "q", cregsymbols.item(x) & "," & q_last_time, "" x = x + 1 loop 'clear out x = 1 do while cregsymbols.count > 0 cregsymbols.remove 1 loopend sub 20210311