需要帮助调试代码! [英] Need help debugging a code!

查看:56
本文介绍了需要帮助调试代码!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作激光笔。我关注了Michael Reeves的一个视频,并将代码完全复制到他编写的内容中,但我收到了一条错误消息。消息中写着'写'有两个参数我不确定如何解决这个问题。请帮助thnx !! (错误在底部,表示Port.Write(String.Format(X {0} Y {1},



什么我试过了:



 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;
使用 System.Diagnostics;

命名空间 laser_pointer
{
public partial class Form1:Form
{
public 秒表观察{ get ; set ; }

public Form1()
{
InitializeComponent();
}

private void Form1_Load( object sender,EventArgs e)
{
watch = Stopwatch.StartNew();
Port.Open();
}

私有 void Form1_MouseMove( object sender,MouseEventArgs e)
{
writeToPort( new Point(eX,eY));
}

public void writeToPort(点坐标)
{
if (watch.ElapsedMilliseconds > 15
{
watch = Stopwatch.StartNew();

Port.Write( String .Format( X {0} Y {1}
(coordinates.X)/(Size.Width / 180 ) ),
(coordinates.Y /(Size.Height / 180 )));
}
}
}
}

解决方案

 Port.Write( String  .Format(  X {0} Y {1}
(coordinates.X)/(Size.Width / 180 )),
(coordinates.Y /(Size.Height / 180 )));
// 分解
string newString = String .Format(
X {0} Y {1}
(coordinates.X)/(Size.Width / 180 ) ), // 你有一个额外的)
(coordinates.Y /(Size.Height) / 180 ));
Port.Write(newString);



删除宽度计算中的额外')'。


解决方案1已经告诉你问题在哪里。

你应该使用程序员的文本编辑器,它们具有显示括号匹配的功能。使用此功能,只需将光标移动到'('of Port.Write()就会向您显示最后一个位于错误的位置。



专业程序员的编辑器具有此功能,而其他功能则包括语法高亮。

Notepad ++主页 [ ^ ]

ultraedit [ ^ ]

Im trying to build a laser pointer. I followed one of Michael Reeves videos, and copied the code exactly how he wrote it, but I am getting an error message. The message reads "'Write' has two arguments" I am unsure of how to fix this problem. plz help thnx!! (The error is towards the bottom where it says "Port.Write(String.Format("X{0}Y{1}",

What I have tried:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace laser_pointer
{
    public partial class Form1 : Form
    {
        public Stopwatch watch { get; set; }

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            watch = Stopwatch.StartNew();
            Port.Open();
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            writeToPort(new Point(e.X, e.Y));
        }

        public void writeToPort(Point coordinates)
        {
            if (watch.ElapsedMilliseconds > 15)
            {
                watch = Stopwatch.StartNew();

                Port.Write(String.Format("X{0}Y{1}",
                (coordinates.X) / (Size.Width / 180)),
                (coordinates.Y / (Size.Height / 180)));
            }
        }
    }
}

解决方案

Port.Write(String.Format("X{0}Y{1}",
                (coordinates.X) / (Size.Width / 180)),
                (coordinates.Y / (Size.Height / 180)));
//Break it up
string newString = String.Format(
  "X{0}Y{1}",
  (coordinates.X) / (Size.Width / 180)), //you have an extra )
  (coordinates.Y / (Size.Height / 180));
Port.Write(newString);


Remove the extra ')' on the width calculation.


Solution 1 already tells you where is the problem.
You should use a programmer's text editor, they have feature which show the parenthesis matching. With this feature, simply moving the cursor to '(' of Port.Write( would have shown you that the closing one was at wrong place.

Professional programmer's editors have this feature and others ones such as syntax highlighting.
Notepad++ Home[^]
ultraedit[^]


这篇关于需要帮助调试代码!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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