Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with "type mismatch" error

Status
Not open for further replies.

rtnMichael

Programmer
Aug 5, 2002
152
US
Hey, I'm having trouble figuring out why this isn't working...can someone shed some light on it for me?

<HTML>
<HEAD>

<script language=&quot;VBScript&quot;>
Option Explicit

Declare Function WNetGetUser& Lib &quot;Mpr&quot; Alias &quot;WNetGetUserA&quot; _
(lpName as Any, ByVal lpUserName$, lpnLength&)

Function CurrentUserName()
Dim ret as long
Dim cbusername as long
Dim username as String

username = Space(256)
ret = WNetGetUser(ByVal 0&, username, cbusername)

If ret = 0 Then
CurrentUserName = Left(username, InStr(username, Chr(0)) - 1)
else CurrentUserName = &quot;&quot;
end if
End Function
</script>
</HEAD>
<BODY>
<P>here's the username: <%CurrentUserName() %></P>

</BODY>
</HTML>


It gives me a type mismatch error, specifically:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CurrentUserName'

I just want to get the username who logged in to the computer, and I've tried so many different ways....Any help would be great.

Thanks
Mike
 
I've noever done this before, but I do know that you're confusing server-side and client-side code. Does this help?

<HTML>
<HEAD>

<%
Option Explicit

Declare Function WNetGetUser& Lib &quot;Mpr&quot; Alias &quot;WNetGetUserA&quot; _
(lpName as Any, ByVal lpUserName$, lpnLength&)

Function CurrentUserName()
Dim ret as long
Dim cbusername as long
Dim username as String

username = Space(256)
ret = WNetGetUser(ByVal 0&, username, cbusername)

If ret = 0 Then
CurrentUserName = Left(username, InStr(username, Chr(0)) - 1)
else CurrentUserName = &quot;&quot;
end if
End Function

theName = CurrentUserName
%>

</HEAD>
<BODY>
<P>here's the username: <%=theName%></P>

</BODY>
</HTML>


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
well, when I place your revised code between the <script language=VBScript></script>, it says I have a syntax error, but won't say where. If I try to place it between the delimiters (<% %>), it says:

Microsoft VBScript compilation error '800a0400'

Expected statement

Option Explicit
^

I really can't see the problem
 
Hello rtnMichael,

[1] vbs cannot call an api function without installing 3rd party ActiveX as some kind of server. So, you cannot use:
Code:
Declare Function WNetGetUser& Lib &quot;Mpr&quot; Alias &quot;WNetGetUserA&quot; _
  (lpName as Any, ByVal lpUserName$, lpnLength&)
This is no-go.

[2] vbs recognizes variable as variant and are late-binding. So simple declare as:
Code:
Dim ret
Dim cbusername
Dim username
etc.

Unless you clear these hurdles, it would be meaningly to look into the logic of the application.

regards - tsuji
 
so how would I go about declaring the WNetGetUser, I can't seem to use it straight forward...unless there's an easier way to get the username of the person logged on to the computer? I'm hoping that's the only problem I have with the code...:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top