| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 38283 | 2003-10-02 10:53:00 | Help with vbscript | Mike (15) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 179860 | 2003-10-06 02:56:00 | Im not sure if you have figured out how to do this yet but if you havent Ive copied your code and added the bits that I think will fix it. Just copy and paste it. Hope it works as Im a bit rusty on VB. Option Explicit Private WithEvents m_pActiveViewEvents As Map Private Declare Function GetUserName Lib " advapi32.dll " Alias " GetUserNameA " _ (ByVal lpBuffer As String, nSize As Long) As Long Private Function MxDocument_BeforeCloseDocument() As Boolean UnSetEvents End Function Private Function MxDocument_OpenDocument() As Boolean SetEvents End Function Public Sub SetEvents() Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Set m_pActiveViewEvents = pMxDoc.PageLayout End Sub Public Sub UnSetEvents() Set m_pActiveViewEvents = Nothing End Sub Private Sub m_pActiveViewEvents_ViewRefreshed(ByVal pView As IActiveView, _ ByVal phase As esriViewDrawPhase, _ ByVal data As Variant, _ ByVal Envelope As IEnvelope) Dim pGC As IgraphicsContainer Dim InfoString as Variant Set pGC = pView pGC.Reset Dim pElement As IElement Set pElement = pGC.Next Do While Not pElement Is Nothing If TypeOf pElement Is ITextElement Then Dim pTextElement As ITextElement Set pTextElement = pElement If UCase(Mid(pTextElement.Text, 1, 5)) = " DATE: " Then pTextElement.Text = " DATE: " & Date End If If UCase(Mid(pTextElement.Text, 1, 5)) = " NAME: " Then pTextElement.Text = " NAME: " & UserName End If If UCase(Mid(pTextElement.Text, 1, 5)) = " FILE: " Then pTextElement.Text = " FILE: " & GetMXDName End If If UCase(Mid(pTextElement.Text, 1,5)) = " INFO: " Then InfoString = " NAME: " & UserName & " DATE: " & Date & " FILE: " & GetMXDName pTextElement.Text = " INFO: " & InfoString End If End If Set pElement = pGC.Next Loop End Sub Function UserName() As String Dim UN As String * 260 GetUserName UN, Len(UN) UserName = UN End Function Function GetMXDName() As String ' each project in the VBE has a pathname Dim pVBProj As VBProject Set pVBProj = ThisDocument.VBProject ' loop through all the projects Dim l As Long, strPath As String For l = 1 To pVBProj.VBE.VBProjects.Count ' 1 based On Error Resume Next strPath = pVBProj.VBE.VBProjects.Item(l).FileName If Err <> 0 Then strPath = " " Err.Clear End If If InStr(1, LCase(strPath), " .mxd " ) > 0 Then GetMXDName = strPath Exit Function End If Next l GetMXDName = " Untitled.mxd " End Function B. |
Barnabas (4562) | ||
| 179861 | 2003-10-06 18:57:00 | Thanks Barnabas, There seems to be something limiting the results, as yet again it's only displayed the first one (Name: Mike). It's very odd :) Mike. |
Mike (15) | ||
| 179862 | 2003-10-06 19:26:00 | Hmmm, that is strange. Can you try something for me and tell me the result. Delete the line that says InfoString = " NAME: " & UserName & " DATE: " & Date & " FILE: " & GetMXDName and replace it with something simple like InfoString = " Just testing " . Then test it to make sure that Just Testing appears when you type in Info. I just want to make sure that it is actually getting the data from the right place. The + or & operator shouldnt make a difference. Might have to dig out my old VB manual. B. |
Barnabas (4562) | ||
| 179863 | 2003-10-06 19:50:00 | If I replace it with InfoString = " Just testing " the result is " Just testing " (correct). Interestingly if I add " and testing again " to the next line, like this: pTextElement.Text = InfoString & " and testing again " it displays that correctly as well: " Just testing and testing again " . If that helps :) Mike. |
Mike (15) | ||
| 179864 | 2003-10-06 20:03:00 | Hmm, starting to get a bit confused now. Can try this and tell me what happens. After the InfoString = " NAME: " & UserName & " DATE: " & Date & " FILE: " & GetMXDName line but before the pTextElement.Text = " INFO: " & InfoString line, can you add msgbox(InfoString) This will bring up the value of InfoString in a popup box. Im just trying to see if it has the correct value stored in the string but just isnt displaying it properly or if it is displaying the whole string, which means our concatenation is wrong. B. |
Barnabas (4562) | ||
| 179865 | 2003-10-06 20:21:00 | I just kept getting a box saying "Name: Mike" - I'd click OK and it'd appear again, usually 3 times before it'd stop. This happened before I even created the text box. Mike. |
Mike (15) | ||
| 179866 | 2003-10-06 20:50:00 | Ok I think I see what is happening. Its going through the do while loop 3 times instead of exiting it. Try putting all of the code back to how we first had it and then after the line pTextElement.Text = " INFO: " & InfoString add the line exit sub B. |
Barnabas (4562) | ||
| 179867 | 2003-10-06 21:29:00 | It still just displays the first part of the infostring (Name: Mike). If I make Date the first part of InfoString, then it only displays the date, and so on. Mike. |
Mike (15) | ||
| 179868 | 2003-10-06 21:48:00 | Fast running out of ideas. Only other thing I can think of is to remove the exit sub line and then in the infostring = " Name: " + e.t.c change to infostring = infostring + " Name " e.t.c. | Barnabas (4562) | ||
| 179869 | 2003-10-06 23:43:00 | This will be my last idea on this, vbscript & vb are now not worth converting too. I'll stick with ASM & C/C++ at least I have ideas of how to fix the problem in C/C++. I think the Do While Loop could be the culprit, I think that after the variable is being passed it includes an end of statement which stops it processing the rest of the line. These are just ideas and unless someone wants to write an error checking function, by all means go ahead, that would help. So here's my last idea and final idea... well maybe If Ucase(Mid(pTextElement.Text, 1, 5)) = " INFO: " Then Dim InfoString InfoString = " NAME: " & UserName InfoString = InfoString & " DATE: " & Date InfoString = InfoString & " FILE: " & GetMXDName pTextElement.text = InfoString End If |
Kame (312) | ||
| 1 2 3 4 | |||||