Sign in to follow this  
Followers 0
youknowwho4eva

Adding multiple variables to a listview

4 posts in this topic

I'm trying to create a simple chat for people in our company. My thought process of doing this is writing an ini file then displaying it in a listview. The help file shows how to put different text in each column, but when I tried with variables, no luck. Also with my testing the text doesn't update when you hit ok, I know I should know this one, but it alloudes me today. Can someone point me in the right direction with these please?

#include <GUIConstantsEx.au3>
opt("guioneventmode",1)
Local $var


GUICreate("Chat")
GUISetOnEvent($gui_event_close, "bye")


    GUICtrlCreateLabel("Chat", 10, 20)
    $list = GUICtrlCreateListView("Who  |Said  ", 10, 10, 200, 150)
    $item1 = GUICtrlCreateListViewItem($var,$list)
    $text = GUICtrlCreateInput($var, 10, 230, 200, 20)
    
    $ok6 = GUICtrlCreateButton("Enter", 200, 280)
    GUISetOnEvent($ok6, "ok")
    

GUISetState()     
    Func ok()
        IniWrite("s:\test\Config.ini", "Chat", "chat", GUICtrlRead($text))
        $var = IniRead("s:\test\Config.ini", "Chat", "chat", "NotFound")
            
    EndFunc
    Func bye()
        Exit
    EndFunc
    
    While 1
        Sleep(100)
        WEnd

Giggity

Share this post


Link to post
Share on other sites



That is pretty much not the best approach... Look at some of the TCP function. they will make instant messaging much easier.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Alright, I'll look into that, but for learning sake, I'm trying some things. I tried this

#include <GUIConstantsEx.au3>
$name = @UserName


Opt('MustDeclareVars', 1)

Example()

Func Example()
    
    Local $add, $clear, $mylist, $msg, $text, $wholist
    
    GUICreate("MP Chat") 

    $add = GUICtrlCreateButton("Add", 150, 190, 75, 25)
    $clear = GUICtrlCreateButton("Clear", 250, 190, 75, 25)
    $mylist = GUICtrlCreateList("MP Chat initialized", 150, 30, 200, 100)
    $text = GUICtrlCreateInput("", 150, 150, 200, 20) 
    $wholist = GUICtrlCreateList("Sender", 25, 30, 100, 25)
    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()

        Select
            Case $msg = $add
                GUICtrlSetData($mylist, guictrlread($text))
                GUICtrlSetData($wholist, $name)
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
                GUICtrlSetData($wholist, "")

        EndSelect
    WEnd
EndFunc

But when you hit add, the text is inserted in the field randomly? is there a way to change that?

Edit: my fault it's not random its alphabetical, can you turn that off? or invert it? I added a time stamp to it, but the messages add to the bottom so when you get to the bottom of the box you have to scroll to see the current message.

Edited by youknowwho4eva

Giggity

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I've solved all the above issues (in some way shape or form), my new issue is listing an array. I create an array of users, but can't get it to list them all in my user status box. how can I fix this?

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>


    $name = @UserName


IniWrite("s:\test\Config.ini", "Users", $name, "online")
Opt('MustDeclareVars', 1)

Example()

Func Example()
    
    Local $add, $clear, $mylist, $msg, $text, $timestamp, $others, $others2 = "", $userlist, $users, $users2
    
    GUICreate("MP Chat", 700, 500) 

    $add = GUICtrlCreateButton("Send", 25, 390, 75, 25, $BS_DEFPUSHBUTTON)
    $clear = GUICtrlCreateButton("Clear", 125, 390, 75, 25)
    $mylist = GUICtrlCreateList("MP Chat initialized", 15, 30, 450, 300)
    $text = GUICtrlCreateInput("", 25, 350, 200, 20) 
    GUICtrlSetState ($text, $GUI_FOCUS)
    $userlist = GUICtrlCreateList("", 485, 30, 200, 150)

    
    GUISetState()
    $timestamp = @HOUR & ":" & @MIN & ":" & @SEC & " " & $name & ": "
    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()

        Select
            Case $msg = $add
                $others2 = $timestamp & guictrlread($text)
                GUICtrlSetData($mylist, $timestamp & guictrlread($text),1)
                GUICtrlSetData($mylist, $timestamp & guictrlread($text),1)
                $timestamp = @HOUR & ":" & @MIN & ":" & @SEC & " " & $name & ": "
                IniWrite("s:\test\Config.ini", "Chat", "chat", $others2)
                GUICtrlSetData($text, "")
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
            
        EndSelect
    $users = IniReadSection("s:\test\Config.ini", "Users")                            ;here is my attempt I'm glad I got this far.
    If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $users[0][0]
        $users2 = $users[$i][0] & "  " & $users[$i][1] & @CRLF
        if $users2 <> $userlist Then
            GUICtrlSetData($userlist,$users2)
            $userlist = $users2
        Else
        EndIf
        
    Next
EndIf
        
                $others = IniRead("s:\test\Config.ini", "Chat", "chat", "")
                if $others <> $others2 and $others2 <> "" Then
                    GUICtrlSetData($mylist, $others)
                    $others2 = $Others
                ElseIf $others2 = "" Then
                    
                Else
                    
                EndIf
            WEnd
            IniWrite("s:\test\Config.ini", "Users", $name, "offline")
EndFunc
Edited by youknowwho4eva

Giggity

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0