webForumDet fria alternativet

array

8 svar · 398 visningar · startad av aleborg

aleborgMedlem sedan jan. 20012 962 inlägg
#1

har ett litet problem
den här koden kollar vilka som är inloggade, men skulle personen lyckas logga in igen så syns personens namn två gånger, hur gör jag så att namnet bara syns en gång:

<% 
user_array=split(Application("active_users"),"*")
for t=0 to ubound(user_array)-1
Response.Write "<tr><td class=ie width=280><a href=medlemmar.asp?ID="& user_array(t) &" class=mark>"& user_array(t) &"</a></td><td class=ie width=329><a href=pm.asp?Pmuser="& user_array(t) &" class=mark>Skicka meddelande</a></td></tr>"
next
%>

samma sak här fast med antal:

<% 
user_array=split(Application("active_users"),"*")
antal=uBound(user_array)
guests=Application("ActiveUsers") - antal
%>
	<% If antal = 1 Then %> <b><%=antal%></b> medlem<% Else %> <b><%=antal%></b> medlemmar<% End If %>
	<% If guests = 1 Then %> och <b><%=guests%></b> gäst<% ElseIF guests=0 Then %><% Else %> och <b><%=guests%></b> gäster.<% End If %>

har sett typ två medlemmar(båda jag) och -1 gäst

LarsGMedlem sedan dec. 200012 465 inlägg
#2

Några frågeställningar

for t=0 to ubound(user_array)-1

varför har du Ubound - 1?

user_array=split(Application("active_users"),"*")
antal=uBound(user_array)
guests=Application("ActiveUsers") - antal

Antal borde vara Ubound(user_array) + 1 då index börjar på 0.

För att undvika att skriva ut samma namn flera gånger så kan man göra så här

<% 
user_array=split(Application("active_users"),"*")
for t = 0 to ubound(user_array)
  found = false
  if t > 0 then
     for i = 0 to t - 1
         if  user_array(i) = user_array(t) then
             found = true
             exit for
         end if
     next
  end if
  if not found then
     Response.Write "<tr><td class=ie width=280><a href=medlemmar.asp?ID="& _
     user_array(t) &" class=mark>"& user_array(t) & _
     "</a></td><td class=ie width=329><a href=pm.asp?Pmuser="& _
     user_array(t) &" class=mark>Skicka meddelande</a></td></tr>"
  end if
next
%>

Det där med -1 gäst måste bero på att värdet activeUsers inte uppdateras. Jag har hört att det är problem med att session_onEnd inte alltid körs beroende på något fel i PWS. (Mest spekulativt, inget definitivt.)
------------------
essentitia preter non sans multiplicandum

[Redigerat av LarsG den 19 apr 2001]

aleborgMedlem sedan jan. 20012 962 inlägg
#3

varför har du Ubound - 1?

Annars får jag en rad utan användarnamn
och endast "Skicka meddelande"

Nu visas inte extra namnet men det står 2 medlemmar trots att jag är ensam(loggat in två gånger men namnet visas 1 gång)!

Jag kör Win2000 Server med IIS5 och alla uppdateringar!

LarsGMedlem sedan dec. 200012 465 inlägg
#4

Ok jag förstår, det ligger en * efter varje namn! Jag trodde det bara låg mellan.
Då kanske du borde lägga till en kolla att du bara sparar namnet en gång i Application("active_users") och har två räknare , en för totala antalet besökare, gäster + inloggade och en för inloggade.

------------------
essentitia preter non sans multiplicandum

aleborgMedlem sedan jan. 20012 962 inlägg
#5

Hur?
global.asa:

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
ReDim TopicName(0)
ReDim TopicDescription(0)

Sub Application_OnStart
	' Set our user count to 0 when we start the server
	Application("ActiveUsers") = 0
 	Application("active_users")=""

     '###########################################################
     ' set title
     Application("Title") = "ASP Chat"
     ' Create your chat rooms below, do not modify anything else/
     CreateRoom "Data", "Diskutera data"
     CreateRoom "Kärlek", "Kärleksnästet"
     CreateRoom "Allmän", "Allt mellan himmel och jord"
     CreateRoom "Sport", "Sportfånar"
     'CreateRoom "Room Name", "Room Description"
     '###########################################################
	 
     Application("TopicNames") = TopicName
     Application("TopicDescriptions") = TopicDescription

     Dim Users()
     Redim Users(1)
     Dim UsersGroup()
     Redim UsersGroup(1)
     Application("Users") = Users
     Application("UsersGroup") = UsersGroup

     Dim UsersIP()
     Redim UsersIP(1)
     Dim UsersTimeOn()
     Redim UsersTimeOn(1)
     Dim UsersIdleOn()
     Redim UsersIdleTime(1)
     Application("UsersIP") = UsersIP
     Application("UsersTimeOn") = UsersTimeOn
     Application("UsersIdleTime") = UsersIdleTime

End Sub

Sub Session_OnStart
	Session("Usname")=""
' Change Session Timeout to 20 minutes (if you need to)
	Session.Timeout = 10
	' Set a Session Start Time
	' This is only important to assure we start a session
	Session("Start") = Now
	' Increase the active visitors count when we start the session
	Application.Lock
		Application("ActiveUsers") = Application("ActiveUsers") + 1
	Application.UnLock
End Sub

Sub Session_OnEnd
	' Decrease the active visitors count when the session ends.
	Application.Lock
		Application("ActiveUsers") = Application("ActiveUsers") - 1
	Application.UnLock
     un=Session("Usname")
     if un<>"" and Application("active_users")<>"" then
	tmp=Application("active_users")
	idx=instr(tmp,un & "*")
	tmp2=left(tmp,idx-1) & right(tmp,len(tmp)-idx-len(un))
	Application("active_users")=tmp2
      end if

    Topic = Session("Topic")
    Name = Session("Name")

    Users = Application("Users")
    UsersIP = Application("UsersIP")
    UsersTimeOn = Application("UsersTimeOn")
    UsersIdleTime = Application("UsersIdleTime")

    Match = 1
    If IsArray(Users) Then
           UsersGroup = Application("UsersGroup")
           NumOfUsers = UBound(Users)
           If NumOfUsers = 1 Then
                 Set Application("Users") = Nothing
                 Set Application("UsersGroup") = Nothing

                 Set Application("UsersIP") = Nothing
                 Set Application("UsersIdleTime") = Nothing
                 Set Application("UsersTimeOn") = Nothing
           Else 
              ReDim UpdatedUsers(1)
              ReDim UpdatedUsersGroup(1)

              ReDim UpdatedUsersIP(1)
              ReDim UpdatedUsersTimeOn(1)
              ReDim UpdatedUsersIdleTime(1)
              For I = 1 To NumOfUsers
                  If Name <> Users(I) Then
                       ReDim Preserve UpdatedUsers(Match)
                       ReDim Preserve UpdatedUsersGroup(Match)
                       UpdatedUsers(Match) = Users(I)
                       UpdatedUsersGroup(Match) = UsersGroup(I)

                       ReDim Preserve UpdatedUsersIP(Match)
                       ReDim Preserve UpdatedUsersTimeOn(Match)
                       ReDim Preserve UpdatedUsersIdleTime(Match)
                       UpdatedUsersIP(Match) = UsersIP(I)
                       UpdatedUsersTimeOn(Match) = UsersTimeOn(I)
                       UpdatedUsersIdleTime(Match) = UsersIdleTime(I)

                       Match = Match + 1
                  End If
              Next
              Application("Users") = UpdatedUsers
              Application("UsersGroup") = UpdatedUsersGroup

              Application("UsersIP") = UpdatedUsersIP
              Application("UsersTimeOn") = UpdatedUsersTimeOn
              Application("UsersIdleTime") = UpdatedUsersIdleTime

           End If
   End If

   Set fileObject = Server.CreateObject("Scripting.FileSystemObject")
   textFile = Application("filebase") & Replace(Topic, "+", "_") & ".txt"
   'If fileObject.FileExists(textfile) Then
         Set inStream = fileObject.OpenTextFile(textFile,1,TRUE,FALSE)
         file = inStream.ReadAll
         Set inStream = Nothing

         file = file & "<FONT SIZE=2 FACE='Vedana,Arial' Color=#808080><b>***[" &  Name & " has exited (" & Now & ")]***</b></FONT><br>"
         Set outStream = fileObject.CreateTextFile(textFile,True)
         outStream.WriteLine(file)
	 outStream.Close
         Set outStream = Nothing
   'End If

   Session("Enter") = True

End Sub
 Sub CreateRoom(Name, Description)
   		nLen = UBound(TopicName)+1
   		ReDim Preserve TopicName(nLen)
   		TopicName(nLen) = Name
   		ReDim Preserve TopicDescription(nLen)
   		TopicDescription(nLen) = Description
		
 End Sub

</SCRIPT>

lite lång ;)

LarsGMedlem sedan dec. 200012 465 inlägg
#6

Jag kan ta en titt på det senare i kväll.

------------------
essentitia preter non sans multiplicandum

aleborgMedlem sedan jan. 20012 962 inlägg
#7

tack

LarsGMedlem sedan dec. 200012 465 inlägg
#8

Har tittat nu, men själva inloggningen är ju inte med.
Det finns dock ställen i session_OnEnd där man skriver i application utan att den är låst. Skall titta närmare på det.

------------------
essentitia preter non sans multiplicandum

aleborgMedlem sedan jan. 20012 962 inlägg
#9

inloggningen ligger ju på första sidan???

129 ms totalt · 3 externa anrop · cache AV · v20260731051352-full.56cc9887
0 ms — hämta statistik (cache)
0 ms — hämta forumlista (cache)
127 ms — hämta tråd, inlägg och bilagor (db)