半城柳色半声笛

文章 评论 浏览 26

半城柳色半声笛 2024-12-24 10:04:53

我的答案看起来更像是评论,但它太长,无法放入评论(并且无法正确格式化)。

如何循环范围

我建议您查看 Chip Pearson 页面 了解有关优化 VBA,尤其是 VBA 中的范围循环。

当您遍历范围时,您应该使用 foreach 语句,如本示例中所述:

Dim WS as Worksheet
For Each WS In Worksheets
    MsgBox WS.Name
Next WS

Dim i as Integer
For i = 1 To Worksheets.Count
    MsgBox Worksheets(i).Name
Next i

查找最后一个空单元格

您的代码似乎尝试查找最后一个空单元格。您可以轻松地使用

With ActiveWorkbook.Worksheets("Sheet1")
    .Cells(.Rows.Count,1).End(xlUp)
End With

您可以在 ozgrid 上找到更多提示(即使它们不要使用rows.count

避免选择

如果您尝试选择循环中的每个单元格,您的代码将会非常非常慢

你最好使用VBA的对象模型
例如,如果您只想复制单元格的

不做

Range("A1").Select
Selection.Copy
Range("A2").Select
Selection.Paste

Range("A2").Value = Range("A1").Value

My answer will better look like a comment but it is too long to fit in a comment (and cannot be formatted properly).

How to loop over a range

I advise you to have a look at Chip Pearson page about optimizing VBA, especially looping over range in VBA.

When you loop over range, you shoul use the for each statement as described in this example:

Dim WS as Worksheet
For Each WS In Worksheets
    MsgBox WS.Name
Next WS

Dim i as Integer
For i = 1 To Worksheets.Count
    MsgBox Worksheets(i).Name
Next i

Finding the last empty cell

Your code seems to try to find the last empty cell. You can do it easily with

With ActiveWorkbook.Worksheets("Sheet1")
    .Cells(.Rows.Count,1).End(xlUp)
End With

You can find some more tips on ozgrid (even if they don't use rows.count)

Avoiding Selects

Your code will be very very slow if you are trying to Select every cell in a loop.

You'd better use the object model of VBA.
For instance, if you only want to copy the value of a cell:

Don't do

Range("A1").Select
Selection.Copy
Range("A2").Select
Selection.Paste

Do

Range("A2").Value = Range("A1").Value

如何将单元格值设置为循环内容?

半城柳色半声笛 2024-12-24 09:23:54

像这样的东西应该可以工作:

container
    .RegisterType<LoaderInputReader>(
        "us",
        new InjectionConstructor(
            @"\\ad1\accounting$\Xml\qb_us.xml",
            new ResolvedParameter<Company>(),
            new ResolvedParameter<eTargets>()));
container
    .RegisterType<LoaderInputReader>(
        "intl",
        new InjectionConstructor(
            @"\\ad1\accounting$\Xml\qb_intl.xml",
            new ResolvedParameter<Company>(),
            new ResolvedParameter<eTargets>()));

这为 LoaderInputReader 的每个注册命名。现在你可以这样解决:

var us = container.Resolve<LoaderInputReader>("us");
var intl = container.Resolve<LoaderInputReader>("intl");

Something like this ought to work:

container
    .RegisterType<LoaderInputReader>(
        "us",
        new InjectionConstructor(
            @"\\ad1\accounting$\Xml\qb_us.xml",
            new ResolvedParameter<Company>(),
            new ResolvedParameter<eTargets>()));
container
    .RegisterType<LoaderInputReader>(
        "intl",
        new InjectionConstructor(
            @"\\ad1\accounting$\Xml\qb_intl.xml",
            new ResolvedParameter<Company>(),
            new ResolvedParameter<eTargets>()));

This names each registration of LoaderInputReader. Now you can resolve like this:

var us = container.Resolve<LoaderInputReader>("us");
var intl = container.Resolve<LoaderInputReader>("intl");

使用 Unity 改变构造函数注入的字符串参数

半城柳色半声笛 2024-12-24 08:26:24
$sql = "SELECT COUNT(*) FROM users WHERE username = '$username'";
$sql = $this->db->quote($sql);

您正在引用整个查询,这没有任何意义,并且从安全角度来看是完全危险的 - 并且可能会导致无效的查询。

这是更正确的代码:

// return TRUE if user is available
public function isUsernameAvailable($username) {
    $sql = "SELECT id FROM users WHERE username = :username";
    $stmt = $this->db->prepare($sql);
    $stmt->execute(array(':username' => $username));

    return $stmt->fetch() === FALSE;
}


if (!$user->isUsernameAvailable($_POST['username'])) {
    echo 'The username is already taken!';
    $error = 1;
}
$sql = "SELECT COUNT(*) FROM users WHERE username = '$username'";
$sql = $this->db->quote($sql);

You are quoting the whole query, this does not make any sense and is outright dangerous from a security standpoint – and probably results in an invalid query anyway.

Here's a more proper code:

// return TRUE if user is available
public function isUsernameAvailable($username) {
    $sql = "SELECT id FROM users WHERE username = :username";
    $stmt = $this->db->prepare($sql);
    $stmt->execute(array(':username' => $username));

    return $stmt->fetch() === FALSE;
}


if (!$user->isUsernameAvailable($_POST['username'])) {
    echo 'The username is already taken!';
    $error = 1;
}

pdo - 用户名已经存在,但还不是

半城柳色半声笛 2024-12-24 05:17:10

目前,RubyMine 依赖 Rails 框架将 CoffeeScript 编译为 JavaScript。

PhpStorm/WebStorm 产品中提供了尖端的 CoffeeScript 支持,EAP 版本将于 2011 年底发布。您可以在 http://confluence.jetbrains.net/display/WI/Web+IDE+EAP

观看该问题以了解进展情况。

最新版本有编译 CoffeeScript 的操作,但它只是显示一个包含结果的窗口,而不写入任何文件(帮助 | 查找操作 | 编译 Coffeescript 文件,或将其绑定到设置 | 键盘映射中的键盘快捷键)。

请注意,它仍在进行中,更多功能很快就会推出。目前,您可能可以使用命令行外部工具来设置编译。

RubyMine relies on Rails framework for CoffeeScript to JavaScript compilation at the moment.

Cutting edge CoffeeScript support is available in PhpStorm/WebStorm products, in the EAP versions to be released by the end of 2011. You can download and try them at http://confluence.jetbrains.net/display/WI/Web+IDE+EAP.

Watch the issue for progress.

Latest version has an action to compile CoffeeScript, but it just displays a window with the result without writing any files (Help | Find Action | Compile Coffeescript File, or bind it to keyboard shortcut in Settings | Keymap).

Note that it's still work in progress, more features will be available soon. At the moment you can probably set up compilation using command line external tools.

适用于 Windows 的 CoffeeScript IDE - 尝试过 Titanium Studio 和 RubyMine

半城柳色半声笛 2024-12-24 05:08:10
def myClassOf[T:ClassTag] = implicitly[ClassTag[T]].runtimeClass
def myClassOf[T:ClassTag] = implicitly[ClassTag[T]].runtimeClass

Scala - 从泛型类型获取类对象

半城柳色半声笛 2024-12-23 13:56:41

下面将做你想做的事。它将打印“一”和“十”。另请注意,它被输入为精确的数组维度 10 和 8。

char my_array[10][8] = 
{
{"One"},
{"Two"},
{"One"},
{"One"},
{"One"},
{"One"},
{"One"},
{"One"},
{"Nine"},
{"Ten"},
};

void foo ( char (**ret)[10][8] )
{
  *ret = my_array;
}

void main()
{
  char (*ret)[10][8];
  foo(&ret);

  printf("%s\r\n", (*ret)[0] )
  printf("%s\r\n", (*ret)[9] )
}

最初的问题是关于返回数组,因此我正在更新它以显示返回值。你不能直接“返回一个数组”,但你可以创建一个数组的 typedef 并返回它......

char my_array[10][8];
typedef char ReturnArray[8];
ReturnArray* foo()
{
  return my_array;
}

The following will do what you want. it will print "One" and "Ten". Also note that it is typed to the exact array dimensions of 10 and 8.

char my_array[10][8] = 
{
{"One"},
{"Two"},
{"One"},
{"One"},
{"One"},
{"One"},
{"One"},
{"One"},
{"Nine"},
{"Ten"},
};

void foo ( char (**ret)[10][8] )
{
  *ret = my_array;
}

void main()
{
  char (*ret)[10][8];
  foo(&ret);

  printf("%s\r\n", (*ret)[0] )
  printf("%s\r\n", (*ret)[9] )
}

The original question was about RETURNING the array, so I'm updating this to show returning a value. You can't "return an array" directly, but you CAN make a typedef of an array and return that...

char my_array[10][8];
typedef char ReturnArray[8];
ReturnArray* foo()
{
  return my_array;
}

在 C 中返回二维字符数组

半城柳色半声笛 2024-12-23 12:41:46

将 newpath 从 更改

List<ArrayList> 

List<DataRow>

change newpath from

List<ArrayList> 

to

List<DataRow>

如何将DataSet转换为List

半城柳色半声笛 2024-12-23 12:06:08

$h2 是一个保存引用的词法变量。更改 $h2 只是替换其中的引用。

%{$h2}$h2 (又名 %b)引用的哈希,因此更改 %{$h2}< /code>(又名 %b)更改 $h2(又名 %b)引用的哈希值。

您似乎期望更改一个变量($h2)会更改另一个变量(%b),但我不知道您为什么有这样的期望。它们甚至不是相同的变量类型!当标量没有元素时(至少与哈希不同),如何尝试通过更改标量来更改哈希的元素。

$h2 is a lexical var that holds a reference. Changing $h2 just replaces the reference therein.

%{$h2} is the hash referenced by $h2 (aka %b), so changing %{$h2} (aka %b) changes the hash referenced by $h2 (aka %b).

You seem to be expecting that changing one variable ($h2) will change another (%b), but I have no idea why you have any such expectation. They're not even the same variable type! How can one even try to change the elements of a hash by changing a scalar when a scalar doesn't have elements (at least not in the same sense as a hash does).

Perl - 传递对子例程的引用

半城柳色半声笛 2024-12-23 10:57:13

关于测试中的随机值和内联方法/变量。
此代码为您的测试生成 100 个随机整数/字符串对。

    [Theory]
    [PropertyData("GetTestData")]
    public void test(int number1, string number2)
    {

        int result = number1 + Convert.ToInt32(number2);
        var expectedType = Type.GetType("System.Int32");
        Assert.IsType(expectedType, result);
    }

    public static IEnumerable<object[]> GetTestData
    {
        get { return Enumerable.Repeat(0, 100).Select(x => GenerateTestData()); }
    }

    private static object[] GenerateTestData()
    {
        var rand = new Random(0);
        return new object[] {rand.Next(0,100), rand.Next(0,100).ToString()};
    }

About random values and inline methods/variables in tests.
This code generates 100 random int/string pairs for your test.

    [Theory]
    [PropertyData("GetTestData")]
    public void test(int number1, string number2)
    {

        int result = number1 + Convert.ToInt32(number2);
        var expectedType = Type.GetType("System.Int32");
        Assert.IsType(expectedType, result);
    }

    public static IEnumerable<object[]> GetTestData
    {
        get { return Enumerable.Repeat(0, 100).Select(x => GenerateTestData()); }
    }

    private static object[] GenerateTestData()
    {
        var rand = new Random(0);
        return new object[] {rand.Next(0,100), rand.Next(0,100).ToString()};
    }

为什么 xunit 不允许测试带参数的方法?

半城柳色半声笛 2024-12-22 21:03:55

嗯,你需要它做什么?我一直在开发一个纯 Python 仪器库,它可以通过几种不同的协议(串行、VXI-11 (LXI)、GPIB (linux-gpib) 和 PyVISA)进行通信,称为 python-ivi,位于此处:http://www.github.com/alexforencich/python-ivi 。它是对可互换虚拟仪器规范的解释。不过,它不是 VISA,因此如果您特别需要 VISA,它不会为您提供帮助。

它是用 python 3 编写的,并在 Linux 中进行了测试,但它应该是跨平台的,因为它是纯 python。 python-vxi11 中 VXI-11 的实现也是纯 python,因此也应该是跨平台的。

就高级驱动程序和抽象而言,该项目仍处于相对早期的开发阶段,但它基本上完成了 PyVISA 在低级接口方面所做的所有工作。

Well, what do you need it to do? I have been working on a pure Python instrument library that can communicate over several different protocols (serial, VXI-11 (LXI), GPIB (linux-gpib), and PyVISA) called python-ivi, located here: http://www.github.com/alexforencich/python-ivi . It is an interpretation of the Interchangeable Virtual Instruments specification. It's not VISA, though, so if you specifically need VISA, it's not going to help you.

It's written in python 3 and tested in linux, but it should be cross-platform as it is pure python. The implementation of VXI-11 in python-vxi11 is also pure python and therefore should also be cross-platform.

The project is still in relatively early development in terms of the higher-level drivers and abstractions, but it does basically everything PyVISA does for low-level interfacing.

VISA API的Linux实现

半城柳色半声笛 2024-12-22 10:58:36

换行符就是问题所在。您有 UNIX 字符,但您期望 Windows 风格的换行符。
我使用给定的 CSV 文件对其进行了转换和测试。

您可以使用 Windows 换行符测试转换后的 CSV 文件:
http://pastebin.com/9CK3JMRc

您可以通过自动检测来修复此问题 ini_set('auto_detect_line_endings' ,真);
或转换字符串。

The newline character is the problem. You have unix chars, but you expect windows-style newlines.
I converted an test it with the given CSV file.

You can test the converted CSV file with windows newlines:
http://pastebin.com/9CK3JMRc

You could fix this in the by autodetection ini_set('auto_detect_line_endings', true);
or convert the strings.

为什么这个 CSV 不能用 fgetcsv 解析?

半城柳色半声笛 2024-12-22 10:31:08

我记得当我编写类似的代码时,我确实遇到了一些奇怪的问题。我不确定您的呼叫失败的确切原因,但您可以扭转问题并执行以下操作:

return group.GetMembers(true).Contains(user);

I remember when I wrote similar code I did run into some strange issues. I'm not sure exactly why your call is failing but you can turn your problem around and do something like:

return group.GetMembers(true).Contains(user);

C# System.DirectoryServices.AccountManagement 未知错误 (0x80005000) UserPrincipal.IsMemberOf()

半城柳色半声笛 2024-12-22 08:28:04

由于无法实现 LV 共享变量协议(如 Tomalak 的帖子所述),启用两者之间通信的最佳选择是使用

  • 另一种消息协议,例如 ZeroMQ,并为 LabVIEW 进行绑定。
  • 使用原始 TCP 或 UDP 套接字,LabVIEW 和 C++ 均支持这两种套接字

Having no way to implement LV shared variable protocol (as Tomalak's post says), your best bet to enable communication between both would be to

  • use another messaging protocol, like ZeroMQ, and make bindings for LabVIEW.
  • use raw TCP or UDP sockets, both being supported in LabVIEW and C++

如何从c++读取写入labview网络共享变量

半城柳色半声笛 2024-12-22 00:22:44

当然,目前不同的人对“引用传递”的含义有不同的定义。这就是为什么他们对于某些东西是否是通过引用传递存在分歧的原因。

但是,无论您使用什么定义,都必须在不同语言中一致使用它。你不能说一种语言具有按值传递,并且在另一种语言中具有完全相同的语义并说它是按引用传递。指出语言之间的类比是解决这一争议的最佳方式,因为尽管人们可能对特定语言的传递模式有强烈的看法,但当你将相同的语义与其他语言进行对比时,有时会带来反直觉的结果,迫使他们重新思考他们的定义。

  • 一种主要观点是 Java 仅是按值传递的。 (在互联网上到处搜索,你都会找到这种观点。)这种观点是对象不是值,而是总是通过引用进行操作,因此引用是按值分配或传递的。这种观点认为,引用传递的测试是是否可以分配给调用范围内的变量。

如果你同意这一观点,那么你还必须考虑大多数语言,包括 Python、Ruby、OCaml、Scheme、Smalltalk、SML、Go、JavaScript、Objective-C 等多种语言。 仅按值传递。如果您觉得这些内容很奇怪或违反直觉,我要求您指出为什么您认为这些语言中的对象的语义与 Java 中的对象的语义不同。 (我知道其中一些语言可能明确声称它们是按引用传递的;但它们所说的无关紧要;必须根据实际行为将一致的定义应用于所有语言。)

  • 如果您采取相反的态度如果认为Java中的对象是按引用传递的,那么您也必须将C视为按引用传递。

以 Java 为例:

class Thing { int x; }
void func(Thing object){ object.x = 42; object = null; }
Thing something = null;
something = new Thing();
func(something);

在 C 中,它相当于:

typedef struct { int x; } Thing;
void func(Thing *object){ object->x = 42; object = NULL; }
Thing *something = NULL;
something = malloc(sizeof Thing);
memset(something, 0, sizeof(something));
func(something);
// later:
free(something);

我声称上面的内容在语义上是等效的;只是语法不同。唯一的语法差异是:

  1. C 需要显式的 * 来表示指针类型; Java 的引用(指向对象的指针)类型不需要显式的 *
  2. C使用->通过指针访问字段; Java 只是使用 .
  3. Java 使用 new 为堆上的新对象动态分配内存; C使用malloc来分配它,然后我们需要初始化内存。
  4. Java 有垃圾收集功能

请注意,重要的是,

  1. 使用对象调用函数的语法在两种情况下都是相同的:func(something),无需执行任何诸如获取地址之类的操作。
  2. 在这两种情况下,对象都是动态分配的(它可能超出函数的范围)。并且
  3. 在这两种情况下,函数内的 object = null; 不会影响调用范围。

因此,两种情况下的语义是相同的,因此如果您调用 Java 传递引用,则也必须调用 C 传递引用。

Sure, different people currently have different definitions of what "pass-by-reference" means. And that is why they disagree on whether something is pass-by-reference or not.

However, whatever definition you use, you must use it consistently across languages. You can't say that one language has pass-by-value, and have the exact same semantics in another language and say that it is pass-by-reference. Pointing out the analogies between languages is the best way to address this dispute, because although people might have strong opinions about the passing modes in particular languages, when you contrast the identical semantics with other languages, it sometimes brings counter-intuitive results that force them to re-think their definition.

  • One predominant view is that Java is pass-by-value only. (Search everywhere on the Internet and you will find this point of view.) This view is that objects are not values, but are always manipulated through references, and thus it is references that are assigned or passed, by value. This view holds that the test of pass-by-reference is whether it is possible to assign to a variable in the calling scope.

If one agrees with this viewpoint, then one must also consider most languages, including as diverse ones as Python, Ruby, OCaml, Scheme, Smalltalk, SML, Go, JavaScript, Objective-C, etc. as pass-by-value only. If any of this strikes you as strange or counterintuitive, I challenge you to point out why you think it is different between the semantics of objects in any of those languages from objects in Java. (I know that the some of these languages may explicitly claim that they are pass-by-reference; but it is irrelevant what they say; a consistent definition must be applied to all languages based on the actual behavior.)

  • If you take the opposing view that objects in Java are pass-by-reference, then you must also consider C as pass-by-reference.

Take your Java example:

class Thing { int x; }
void func(Thing object){ object.x = 42; object = null; }
Thing something = null;
something = new Thing();
func(something);

in C, it would be equivalent to this:

typedef struct { int x; } Thing;
void func(Thing *object){ object->x = 42; object = NULL; }
Thing *something = NULL;
something = malloc(sizeof Thing);
memset(something, 0, sizeof(something));
func(something);
// later:
free(something);

I claim that the above are semantically equivalent; only the syntax is different. The only syntax differences are:

  1. C requires an explicit * to denote a pointer type; Java's reference (pointers to objects) types don't need an explicit *.
  2. C uses -> to access a field through a pointer; Java just uses .
  3. Java uses new to dynamically allocate memory for a new object on the heap; C uses malloc to allocate it, and then we need to initialize the memory.
  4. Java has garbage collection

Note that, importantly,

  1. The syntax for calling the function with the object are the same in both cases: func(something), without needing to do anything like taking address or anything.
  2. In both cases, the object is dynamically-allocated (it may live beyond the scope of the function). And
  3. In both cases, the object = null; inside the function does not affect the calling scope.

So the semantics are the same in both cases, so if you call Java pass-by-reference you must call C pass-by-reference too.

“按引用传递”到底是什么意思?意思是?

半城柳色半声笛 2024-12-21 13:32:47

您可以利用工作集将项目放入逻辑组中。

You can make use of Working Sets to put projects into logical groups.

我可以将 Eclipse 设置为仅针对当前项目发出错误、警告等吗?

更多

推荐作者

泛泛之交

文章 0 评论 0

音栖息无

文章 0 评论 0

荆棘i

文章 0 评论 0

泛滥成性

文章 0 评论 0

我还不会笑

文章 0 评论 0

假扮的天使

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文