我该如何编写“ debug msg”消息?到控制台还是其他旧网站? [英] How can I write a "debug msg" to the console or elsewise in an old web site?

查看:91
本文介绍了我该如何编写“ debug msg”消息?到控制台还是其他旧网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为使用VBScript的旧网站(如 olde中的 old;如Rip-van-Winkle olde中的)添加一些功能。



我的问题的结果是某些逻辑似乎总是等同于单个结果(IsNewBusiness显然总是被赋值为FALSE),而有时却应等同于相反,该逻辑为:

  IsNewBusiness = TRUE'默认(如果未找到记录)
如果未使用adoRS.EOF,则
IsNewBusiness = adoRS.Fields。项目(0)。值<> 0
结束如果

因此,由于逻辑总是等于false,因此我必须假定以下行:

  IsNewBusiness = adoRS.Fields.Item(0).Value< 0 

...已到达,并且adoRS.Fields.Item(0).Value为始终为0



如上面的代码所示,IsNewBusiness布尔值设置为TRUE开头,但始终保持为true,尽管应该(重置)为在某些情况下为TRUE(在给定某些参数的情况下,查询结果应返回值 -1而不是0)。



此问题与但确实独立我在



如何使用VBScript或javascript或其他方式完成警报或控制台日志消息,或诸如此类?



UPDATE



我什至尝试了一些内联JavaScript,例如:

  adoRS.Close()

< script language = javascript>
window.alert(通过IsNewBusiness逻辑实现);
< / script>

...但它炸毁了...



UPDATE 2



我尝试了库尔·丁金(Kul-Tigin)提到的技巧,但似乎对我没有用。



我更改了此代码:

  currentYear = Year(Now)
SQLString = Select MasterUnitsprojSales的NewBiz,其中CYear =&当前年度 and Unit =’&单位和'
adoRS.Open(SQLString,adoCon)
IsNewBusiness = TRUE'默认值(如果未找到记录)
如果没有adoRS.EOF,则
IsNewBusiness = adoRS.Fields。项目(0)。值<> 0’达到了吗?
如果If
adoRS.Close()

...结束:

  currentYear = Year(Now)
SQLString =从MasterUnitsprojSales中选择NewBiz,其中CYear =&当前年度 and Unit =’&单位和'
adoRS.Open(SQLString,adoCon)
IsNewBusiness = TRUE'默认值(如果未找到记录)
ReturnMsg =在If Not adoRS.EOF块之前
Response.Write(< script type =文本/ javascript>& vbCrLf)
Response.Write(<!-& vbCrLf)
Response.Write ( alert('& ReturnMsg&');& vbCrLf)
Response.Write(->& vbCrLf)
Response.Write(< /脚本>& vbCrLf)
如果不是adoRS.EOF,则
IsNewBusiness = adoRS.Fields.Item(0).Value<> 0’达到了吗?
ReturnMsg =已输入If Not adoRS.EOF块
Response.Write(< script type = text / javascript>& vbCrLf)
响应。 Write(<!-& vbCrLf)
Response.Write( alert('& ReturnMsg&');& vbCrLf)
Response.Write(- ->& vbCrLf)
Response.Write(< / script>& vbCrLf)
如果
adoRS.Close()

...运行站点以转到该页面,选择查看源,搜索 If Not adoRS.EOF块,然后没有比赛。我做错了吗?



更新3



我也尝试过此操作(以上内容基于现有代码在页面中,以下内容基于评论者的摘要):

  Response.Write(<!-如果不是adoRS.EOF块->)
如果不是adoRS.EOF则
IsNewBusiness = adoRS.Fields.Item(0).Value< 0’达到了吗?
Response.Write(<!-If Not adoRS.EOF块之后->)
End If



更新4



唯一能够获取已添加到视图源中的调试消息的方法是插入一些抛出错误的javascript。添加此javascript:

 < script language = javascript> 
window.alert(在If Not adoRS.EOF块js之前);
< / script>

在某些情况下:

  Response.Write(<!-在If Not adoRS.EOF块之前->)
< script language = javascript>
window.alert(在If Not adoRS.EOF块js之前);
< / script>
如果不是adoRS.EOF,则

...导致此内容出现在页面上:

  / EMS / customerreportingnet应用程序中的服务器错误。 
---------------------------------------------- ----------------------------------

编译错误
说明:在为该请求提供服务所需的资源的编译过程中发生错误。请查看以下特定的错误详细信息,并适当地修改您的源代码。

编译器错误消息:BC30636:>。

源错误:



第129行:IsNewBusiness = TRUE'默认(如果未找到记录)
第130行:响应。 Write(<!-If Not adoRS.EOF块之前->)
第131行:< script language = javascript>
第132行:window.alert(在If Not adoRS.EOF块js之前);
第133行:< / script>


源文件:C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx行:131

...而这在视图中来源:

 第129行:IsNewBusiness = TRUE'默认值(如果未找到记录)
第130行:Response.Write(&& lt!-在If Not adoRS.EOF块之前-& & quot)
< font color = red>第131行:< script language =& quot; javascript& quot;& gt;
< / font>第132行:window.alert(&在If Not adoRS.EOF块js之前);
第133行:& lt; / script& gt;< / pre>< / code>

...看来,我仍然在利维坦(Leviathan)出没的水域上游游泳。 p>

解决方案

让我们调试一下。情况必须是三件事之一:


  1. 代码已运行,并输入 If ,并将 IsNewBusiness 设置为true。

  2. 运行代码,并输入 If ,并将 IsNewBusiness 设置为false。

  3. 代码已运行,并且没有输入如果。因此,必须将 IsNewBusiness 设置为true。

  4. 该代码永远不会首先运行。 IsNewBusiness 的值未知。

稍加思考就能说服您这些情况是详尽无遗的:其中之一必须是正在发生的事情。



那么,您的工作就是弄清楚这四种情况中的哪一种实际上正在发生。理想情况下,您可以使用调试器连接到该站点(是否使用过Visual Studio的附加到进程选项?)并在代码中设置断点,然后查看哪些断点会被命中,哪些不会。



但是,无论出于什么原因,您都不能使用调试器。因此,如果是我,请使用 Response.Write() Trace()调用来注释代码正如评论中的几个人所建议的那样,发出输出,以指示尽可能多的可能性。由于 Response.Write()是关于代码是否运行(无论您看到还是不看到输出)的绝妙礼物,因此,它是一个不错的选择。案例1和2合并为一个案例(现在,您可能只关心计算机是否进入 If ,而不关心计算机到达那里之后的内部代码) 。



所以我暂时对这样的代码进行注释:

  IsNewBusiness = TRUE'默认值(如果未找到记录)
如果不是adoRS.EOF,则
IsNewBusiness = adoRS.Fields.Item(0).Value< 0
Response.Write( h1 INSIDE IF // h1))
其他
Response.Write( h1  INSIDE ELSE< / h1))
End if

(简而言之:在调试时,您可以安全地更改页面本身的内容为了回答问题,只要您稍后清理突变!)



然后,您可以在加载页面时回答上述情况:




  • 如果以粗体显示 INSIDE IF,则说明计算机位于 If 语句,而 adoRS.EOF 必须为假。

  • 如果您以粗体显示 INSIDE ELSE,则表示知道计算机没有放在 If 语句中,并且必须输入 adoRS.EOF 是。

  • 如果您都看不到,则计算机根本无法访问此代码,而问题出在其他地方。


I'm adding a bit of functionality to an old ("old" as in "olde"; as in Rip-van-Winkle olde) website that uses VBScript.

The upshot of my problem is that certain logic seems to always equate to a single result (IsNewBusiness is always apparently assigned a value of FALSE), whereas it should sometimes equate to the opposite, that logic being:

IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
    IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
End If

So, since the logic is always equating to false, I have to assume that this line:

IsNewBusiness = adoRS.Fields.Item(0).Value <> 0

...is being reached, and that adoRS.Fields.Item(0).Value is always 0

As you can see in the above code, the IsNewBusiness Boolean is set to TRUE to start with, but never remains true, although it should be (reset) to TRUE on some occasions (the query result should, given certain parameters, return a value of "-1" rather than 0).

This question is related to but really separate from a question I asked here:

So, to get to the crux of the biscuit, I want to make absolutely certain that the if block shown above is being reached, by writing out a "debug msg" to the console or something similar.

Based on legacy code in this site, I made this attempt to partner with javascript to those ends:

ReturnMsg = "Made it to IsNewBusiness logic"
Response.Write("<script type=""text/javascript"">" & vbCrLf)
Response.Write("alert ('" & ReturnMsg & "');" & vbCrLf)
Response.Write("</script>" & vbCrLf)

...but it doesn't seem to work - I never see that msg.

I also tried this:

Response.Write("window.alert(ReturnMsg);")

...and this:

Response.Write("console.log(ReturnMsg);")

...with no difference in results. All that I see in my console is:

How can I accomplish an "alert" or a console log msg, or some such, using either VBScript, or javascript, or whatever?

UPDATE

I even tried some inline javascript, like so:

adoRS.Close()

<script language="javascript">
window.alert("Made it past the IsNewBusiness logic");
</script>

...but it blew up...

UPDATE 2

I tried the trick mentioned by Kul-Tigin, but it didn't seem to work for me.

I changed this code:

currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
    IsNewBusiness = adoRS.Fields.Item(0).Value <> 0 'Is this ever reached?
End If
adoRS.Close()

...to this:

currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
ReturnMsg = "Before the If Not adoRS.EOF block"
                Response.Write("<script type=""text/javascript"">" & vbCrLf)
                Response.Write("<!--" & vbCrLf)
                Response.Write("alert ('" & ReturnMsg & "');" & vbCrLf)
                Response.Write("-->" & vbCrLf)
                Response.Write("</script>" & vbCrLf)
If Not adoRS.EOF Then
    IsNewBusiness = adoRS.Fields.Item(0).Value <> 0 'Is this ever reached?
    ReturnMsg = "Entered the If Not adoRS.EOF block"
                Response.Write("<script type=""text/javascript"">" & vbCrLf)
                Response.Write("<!--" & vbCrLf)
                Response.Write("alert ('" & ReturnMsg & "');" & vbCrLf)
                Response.Write("-->" & vbCrLf)
                Response.Write("</script>" & vbCrLf)
End If
adoRS.Close()

...ran the site to get to that page, selected View Source, searched for "the If Not adoRS.EOF block", and there were no matches. Am I doing it wrong?

UPDATE 3

I also tried this (the above was based on existing code in the page, the below is based on the commenter's snippet):

Response.Write("<!-- Before the If Not adoRS.EOF block -->")
If Not adoRS.EOF Then
    IsNewBusiness = adoRS.Fields.Item(0).Value <> 0 'Is this ever reached?
    Response.Write("<!-- After the If Not adoRS.EOF block -->")
End If

UPDATE 4

The only way I was able to get the debug msg I added to show up in the View Source was to insert some javascript that threw an error. Adding this javascript:

<script language="javascript">
    window.alert("Before the If Not adoRS.EOF block js");
</script>

In some context:

Response.Write("<!-- Before the If Not adoRS.EOF block -->")
<script language="javascript">
    window.alert("Before the If Not adoRS.EOF block js");
</script>
If Not adoRS.EOF Then

...caused this to appear on the page:

Server Error in '/EMS/customerreportingnet' Application.
--------------------------------------------------------------------------------

Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: BC30636: '>' expected.

Source Error:



Line 129:        IsNewBusiness = TRUE 'default (if record not found)
Line 130:        Response.Write("<!-- Before the If Not adoRS.EOF block -->")
Line 131:        <script language="javascript">
Line 132:            window.alert("Before the If Not adoRS.EOF block js");
Line 133:        </script>


Source File: C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx    Line: 131 

...and this in the View Source:

Line 129:        IsNewBusiness = TRUE 'default (if record not found)
Line 130:        Response.Write(&quot;&lt;!-- Before the If Not adoRS.EOF block --&gt;&quot;)
<font color=red>Line 131:        &lt;script language=&quot;javascript&quot;&gt;
</font>Line 132:            window.alert(&quot;Before the If Not adoRS.EOF block js&quot;);
Line 133:        &lt;/script&gt;</pre></code>

...so I'm still swimming upstream in Leviathan-infested waters, it seems.

解决方案

Let's debug this. One of three things must be the case:

  1. The code is run, and enters the If, and sets IsNewBusiness to true.
  2. The code is run, and enters the If, and sets IsNewBusiness to false.
  3. The code is run, and doesn't enter the If. Therefore, IsNewBusiness must be set to true.
  4. The code is never run in the first place. IsNewBusiness has an unknown value.

A little bit of thinking will convince you that those cases are exhaustive: One of them must be what's happening.

Your job, then, is to figure out which of those four cases is actually happening. Ideally, you could attach to the site with a debugger (have you used Visual Studio's "Attach to Process" option?) and set breakpoints in the code and just see which breakpoints get hit and which don't.

But let's say you can't use a debugger, for whatever reason. So if it were me, I'd annotate the code with Response.Write() or Trace() calls to emit output, as several people suggested in the comments, to indicate as many of the possibilities as possible. Since Response.Write() is a dead giveaway as to whether the code ran (you either see its output or you don't), it's a good choice. Cases 1 and 2 collapse into a single case (right now, you probably only care whether the computer got into the If, not what the code inside did after the computer got there).

So I'd temporarily annotate the code like this:

IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
    IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
    Response.Write("<h1>INSIDE IF</h1>")
Else
    Response.Write("<h1>INSIDE ELSE</h1>")
End If

(In short: When debugging, you can safely mutate the content of the page itself in order to answer questions, as long as you clean up your mutations later!)

This then allows you to answer the cases above when you load the page:

  • If you see "INSIDE IF" in big bold text, you know that the computer went inside the If statement, and adoRS.EOF must be false.
  • If you see "INSIDE ELSE" in big bold text, you know the computer didn't go inside the If statement, and adoRS.EOF must be true.
  • If you see neither, the computer never reached this code at all, and your problem is elsewhere.

这篇关于我该如何编写“ debug msg”消息?到控制台还是其他旧网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆